/*
 * File: common.css
 * Description: Design tokens, reset and the shared components of the house
 *              frontend. Part of house-frontend; a project never edits it and
 *              puts what it adds in its own stylesheet, loaded after this one.
 */

:root {
    /* ========================================
       LAYOUT AND SPACING
       ======================================== */
    --bp-desktop: 1200px;           /* Desktop breakpoint - documentation only */
    --bp-tablet: 768px;             /* Tablet breakpoint - documentation only */
    --content-max-width: 1500px;    /* Max readable width */
    --content-padding: 20px;        /* Default horizontal padding */
    --content-padding-mobile: 5px;  /* Mobile horizontal padding */
    --content-min-width: 360px;     /* Minimum layout width */
    --space-minimal: 5px;           /* Tightest spacing */
    --space-small: 10px;            /* Small spacing */
    --space-medium: 15px;           /* Medium spacing */
    --space-large: 20px;            /* Large spacing */

    /* ========================================
       BORDERS AND RADII
       ======================================== */
    --border-strong: 4px;           /* Emphasis border (accent stripe) */
    --radius-sm: 4px;               /* Panels, inputs, buttons */
    --radius-md: 8px;               /* Cards */
    --radius-pill: 999px;           /* Badges */

    /* ========================================
       TYPOGRAPHY
       ======================================== */
    --font-xs: 12px;                /* Badges, labels */
    --font-sm: 14px;                /* Metadata, secondary text */
    --font-base: 16px;              /* Default body */
    --font-md: 18px;                /* Inputs, buttons, subheadings */
    --font-lg: 22px;                /* Main headings */
    --font-display: 64px;           /* The one figure a page shows large - an error code */
    --letter-spacing-sm: 0.5px;     /* Subtle letter spacing */

    /* ========================================
       COMPONENT SIZING
       ======================================== */
    --button-padding-block: 10px;   /* Vertical padding for buttons */
    --button-padding-inline: 20px;  /* Horizontal padding for buttons */
    --floating-button-size: 44px;   /* Size of the floating info button */
    --floating-button-offset: 20px; /* Its distance from the edges */
    --overlay-padding-top: 90px;    /* Top padding for overlay content */
    --text-pad-inline: 10px;        /* Horizontal padding for inline text */
    --text-margin-inline: 5px;      /* Horizontal margin for inline text */
    --dropdown-max-height: 200px;   /* Maximum height for dropdown lists */
    --list-max-height: 400px;       /* Scrollable list of a project's own inside a dialog */
    --chart-height: 260px;          /* A chart canvas (chart.js) */

    /* ========================================
       MOTION
       ======================================== */
    --transition-fast: 0.15s;       /* Hover effects */
    --transition-normal: 0.2s;      /* Indicators, dropdowns */
    --transition-slow: 0.3s;        /* Overlays, entry animations */
    --ease-out: cubic-bezier(0.25, 0, 0.2, 1);  /* Shared easing curve */
    --loading-sweep: 1.2s;          /* One pass of a loading bar or sheen */
    --loading-bar-thickness: 3px;   /* The loading bar along an edge */

    /* ========================================
       LIGHT MODE COLORS (default)
       ======================================== */
    --surface-muted: #f8f8f8;       /* Page background */
    --card-bg: #fff;                /* Card / main container */
    --panel-bg: #f9f9f9;            /* Nested panel */
    --panel-alt-bg: #f1f1f1;        /* Alternate panel, buttons, tags */
    --header-bg: #f0f0f0;           /* Header - a distinct plane, not --card-bg */
    --card-border: #e0e0e0;         /* Card border */
    --panel-border: #ddd;           /* Panel border */
    --frame-border: #ccc;           /* Inputs, buttons */
    --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);  /* Card elevation */
    --text-strong: #333;            /* Primary text */
    --muted-text: #555;             /* Secondary text */
    --text-inverse: #fff;           /* Ink on a filled accent surface */
    --accent-primary: #007BFF;      /* Primary accent - a mark, never a fill */
    --accent-link: #0b63ce;         /* Links */
    --accent-hover: #eee;           /* Hover fill */
    --badge-success-bg: #d4edda;    /* Success badge bg */
    --badge-success-text: #155724;  /* Success badge text */
    --badge-danger-bg: #f8d7da;     /* Error badge bg */
    --badge-danger-text: #721c24;   /* Error badge text */
    --badge-warn-bg: #fdf3e0;       /* Warning badge bg - only where something warns */
    --badge-warn-text: #8a5b00;     /* Warning badge text */
    --mark-bg: yellow;              /* <mark> highlight background */
    --mark-text: #000;              /* <mark> highlight text */
    --chart-1: #0b63ce;             /* Chart series 1 - the palette inside a plot only */
    --chart-2: #b35c00;             /* Chart series 2 */
    --chart-3: #2e7d32;             /* Chart series 3 */
    --chart-4: #8e24aa;             /* Chart series 4 */

    /* Tells the browser to paint its own widgets (scrollbars, checkboxes, the
       file picker) for the active theme instead of the light default. */
    color-scheme: light dark;
}

/* ========================================
   DARK MODE COLOR OVERRIDES
   Colors only - no layout or spacing changes.
   ======================================== */
@media (prefers-color-scheme: dark) {
    :root {
        --surface-muted: #1a1a1a;
        --card-bg: #1e1e1e;
        --panel-bg: #252525;
        --panel-alt-bg: #2a2a2a;
        --header-bg: #252525;
        --card-border: #3a3a3a;
        --panel-border: #404040;
        --frame-border: #4a4a4a;
        --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
        --text-strong: #e0e0e0;
        --muted-text: #b0b0b0;
        --text-inverse: #101010;
        --accent-primary: #4a9eff;
        --accent-link: #5ba3ff;
        --accent-hover: #2a2a2a;
        --badge-success-bg: #1a4d2e;
        --badge-success-text: #7ddf64;
        --badge-danger-bg: #4d1a1a;
        --badge-danger-text: #ff8080;
        --badge-warn-bg: #3a2f18;
        --badge-warn-text: #ffcf7a;
        --mark-bg: #665500;
        --mark-text: #ffeb3b;
        --chart-1: #5ba3ff;
        --chart-2: #ffb35c;
        --chart-3: #7ddf64;
        --chart-4: #d68cf0;
    }
}

/* ========================================
   RESET
   Minimal and hand-written; no reset library.
   ======================================== */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    font-family: 'Roboto', Arial, sans-serif;
    margin: 0;
    padding: 0;
    line-height: 1.5;
    min-width: var(--content-min-width);
    background-color: var(--surface-muted);
    color: var(--text-strong);
}

h1, h2, h3, h4, h5, h6 {
    margin: 0;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-strong);
}

h1 {
    font-size: var(--font-lg);
}

h2,
h3 {
    font-size: var(--font-md);
}

h4 {
    font-size: var(--font-base);
}

p {
    margin: 0;
    line-height: 1.5;
}

a {
    color: var(--accent-link);
    text-decoration: none;
    word-break: break-word;
    overflow-wrap: break-word;
}

a:hover {
    text-decoration: underline;
}

/* Markers stay on prose lists; a list that is a component turns them off itself. */
ul, ol {
    margin: 0;
    padding: 0;
}

code {
    background: var(--panel-bg);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-family: 'Roboto Mono', monospace;
    font-size: var(--font-sm);
}

mark {
    background-color: var(--mark-bg);
    color: var(--mark-text);
}

/* ========================================
   SCROLLBARS (both engines)
   ======================================== */
* {
    scrollbar-color: var(--panel-border) var(--panel-bg);
}

*::-webkit-scrollbar-track {
    background: var(--panel-bg);
}

*::-webkit-scrollbar-thumb {
    background-color: var(--panel-border);
    border-radius: var(--radius-sm);
    border: 2px solid var(--panel-bg);
}

*::-webkit-scrollbar-thumb:hover {
    background-color: var(--frame-border);
}

/* ========================================
   MAIN CONTAINER
   Horizontal padding only - vertical rhythm belongs to the page's own gap.
   ======================================== */
main {
    padding: 0 var(--content-padding);
    max-width: var(--content-max-width);
    margin: 0 auto;
}

@media (max-width: 767px) {
    main {
        padding: 0 var(--content-padding-mobile);
    }

    /* Ninety pixels above a dialog is a tenth of a phone screen spent on
       nothing, and it comes off the space the dialog has to say what it
       came to say. */
    :root {
        --overlay-padding-top: var(--space-large);
    }
}

/* ========================================
   FORM ELEMENTS
   Styled on the element selector - one neutral button style is the whole
   vocabulary. A variant class is an addition to record, not a default.
   ======================================== */
input[type="text"],
input[type="search"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
    background-color: var(--card-bg);
    color: var(--text-strong);
    border: 1px solid var(--frame-border);
    border-radius: var(--radius-sm);
    font-family: inherit;
}

input::placeholder,
textarea::placeholder {
    color: var(--muted-text);
}

/* The padding is for a labelled button; a component whose button carries an
   icon alone (the floating ones, the pills) sets its own. */
button,
input[type="submit"],
input[type="button"] {
    padding: var(--button-padding-block) var(--button-padding-inline);
    background-color: var(--panel-alt-bg);
    color: var(--text-strong);
    border: 1px solid var(--frame-border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    cursor: pointer;
}

button:hover,
input[type="submit"]:hover,
input[type="button"]:hover {
    background-color: var(--panel-bg);
}

/* A control that cannot act yet stays visible and says so, like a pill. */
button:disabled,
input[type="submit"]:disabled,
input[type="button"]:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

button:disabled:hover,
input[type="submit"]:disabled:hover,
input[type="button"]:disabled:hover {
    background-color: var(--panel-alt-bg);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* A button that destroys something says so in its ink and fills only on
   hover; it stays the neutral button otherwise, never a red block. */
.button-danger {
    color: var(--badge-danger-text);
}

.button-danger:hover {
    background-color: var(--badge-danger-bg);
}

input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--accent-primary);
}

/* ========================================
   CARDS AND SURFACES
   A card is a plain box; spacing between its children is the page's job.
   ======================================== */
.card {
    padding: var(--space-medium);
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    box-shadow: var(--card-shadow);
}

.card-small {
    padding: var(--space-small);
    background-color: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-sm);
}

/* ========================================
   BADGES
   A status word, not a control: no border, no hover, no cursor.
   ======================================== */
/* Without a modifier a badge is the neutral state - not yet, unknown. */
.badge {
    display: inline-block;
    padding: var(--space-minimal) var(--space-small);
    border-radius: var(--radius-pill);
    background-color: var(--panel-alt-bg);
    color: var(--muted-text);
    font-size: var(--font-xs);
    font-weight: 600;
    text-align: center;
}

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

.badge--danger {
    background-color: var(--badge-danger-bg);
    color: var(--badge-danger-text);
}

/* Only where the project genuinely warns about something. */
.badge--warn {
    background-color: var(--badge-warn-bg);
    color: var(--badge-warn-text);
}

/* ========================================
   PILL ACTIONS
   A compact row of small commands - sharing, downloads, exports. The one
   sanctioned button variant; it stays neutral, the accent never fills it.
   ======================================== */
.action-row {
    display: flex;
    align-items: center;
    gap: var(--space-small);
    flex-wrap: wrap;
}

.pill-button {
    display: inline-flex;
    align-items: center;
    gap: var(--space-minimal);
    padding: 4px 10px;
    border: 1px solid var(--frame-border);
    border-radius: var(--radius-pill);
    background: var(--panel-alt-bg);
    color: var(--text-strong);
    font-family: inherit;
    font-size: var(--font-xs);
    line-height: 1;
    cursor: pointer;
    transition: background-color var(--transition-fast),
                border-color var(--transition-fast);
}

.pill-button:hover {
    background: var(--accent-hover);
    border-color: var(--muted-text);
}

/* Confirmation after a copy - the success badge colours, for two seconds.
   The :hover rule above outranks a single class, and the pointer is still on
   the button that was just clicked, so the confirmation has to hold it. */
.pill-button--copied,
.pill-button--copied:hover {
    background: var(--badge-success-bg);
    color: var(--badge-success-text);
    border-color: var(--badge-success-text);
}

/* A pill waiting for data it cannot act on yet stays visible and inert. */
.pill-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pill-button:disabled:hover {
    background: var(--panel-alt-bg);
    border-color: var(--frame-border);
}

/* ========================================
   OVERLAYS
   One pattern for every modal. JS only toggles .is-visible.
   ======================================== */
.floating-overlay {
    display: flex;
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.35);
    justify-content: center;
    align-items: flex-start;
    padding-top: var(--overlay-padding-top);
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-slow) var(--ease-out),
                visibility var(--transition-slow);
}

.floating-overlay.is-visible {
    opacity: 1;
    visibility: visible;
}

.floating-message {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    box-shadow: var(--card-shadow);
    padding: var(--space-large);
    max-width: 520px;
    width: calc(100% - 40px);
    border: 1px solid var(--card-border);
    text-align: center;
    /* The overlay is fixed, so a dialog taller than the screen is simply cut
       off and the page behind it will not scroll to reveal the rest. Every
       dialog therefore caps itself and scrolls; dvh rather than vh because a
       phone's address bar is part of vh and is not part of the screen. */
    max-height: calc(100vh - var(--overlay-padding-top) - var(--space-large));
    max-height: calc(100dvh - var(--overlay-padding-top) - var(--space-large));
    overflow-y: auto;
}

.floating-message p {
    margin: 0 0 var(--space-medium);
    color: var(--text-strong);
    font-size: var(--font-md);
    line-height: 1.4;
}

.floating-message button {
    padding: var(--button-padding-block) var(--button-padding-inline);
    font-size: var(--font-base);
    font-weight: 600;
}

/* Centred in every dialog, whatever the text around it does. Without a rule
   of its own the button simply follows the parent's text-align, so it sat in
   the middle of a message and on the left of a .dialog-wide - the same
   control closing two dialogs in two different places. */
.floating-close {
    display: block;
    margin-inline: auto;
}

/* A dialog larger than a message adds a modifier next to .floating-message.
   It keeps the height cap and the scroll of .floating-message: a plain vh
   here would count a phone's address bar as part of the screen again. */
.dialog-wide {
    max-width: 600px;
    text-align: left;
}

/* A dialog holding a form rather than a message: a left-aligned column whose
   gaps come from the flex layout, closed by its row of actions. */
.dialog-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-medium);
    text-align: left;
}

.dialog-form p {
    margin: 0;
    font-size: var(--font-base);
}

/* The confirming button first, the closing one after it, both at the end of
   the row. The close button centres itself everywhere else. */
.dialog-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: var(--space-small);
}

.dialog-actions .floating-close {
    margin-inline: 0;
}

/* ========================================
   FILTER LIST
   The checkbox list inside a .dialog-wide overlay - the house way to narrow
   a listing. What is selected lives in the URL, not in the dialog
   (js/filter-dialog.js). The list has no height cap of its own: the dialog
   scrolls, and a scroller inside a scroller leaves a reader on a touch
   screen unable to tell which of the two a finger has hold of.
   ======================================== */
/* Qualified by the dialog, because .floating-message p - the size of a
   one-line notice - would otherwise outrank it. The heading above keeps its
   distance for the same reason: the reset takes every heading margin away. */
.floating-message .filter-description {
    margin-bottom: var(--space-medium);
    color: var(--muted-text);
    font-size: var(--font-sm);
}

.dialog-wide h2 {
    margin-bottom: var(--space-small);
}

/* The select-all row is separated from the options by its own rule. */
.select-all-label {
    margin-bottom: var(--space-small);
    padding: var(--space-small);
    border-bottom: 2px solid var(--panel-border);
}

.filter-options {
    display: flex;
    flex-direction: column;
    gap: var(--space-small);
    margin-bottom: var(--space-large);
    padding: var(--space-small);
    background: var(--surface-muted);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-sm);
}

.filter-checkbox-label {
    display: flex;
    align-items: center;
    gap: var(--space-small);
    padding: var(--space-minimal);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color var(--transition-normal);
}

.filter-checkbox-label:hover {
    background-color: var(--accent-hover);
}

/* ========================================
   FLOATING INFO BUTTON
   Hover is reversed compared to an ordinary button. It is not hidden on
   mobile: it is often the only route to what the about dialog holds.
   ======================================== */
.floating-info-button {
    position: fixed;
    bottom: var(--floating-button-offset);
    right: var(--floating-button-offset);
    width: var(--floating-button-size);
    height: var(--floating-button-size);
    border-radius: 50%;
    border: 1px solid var(--frame-border);
    background: var(--panel-bg);
    color: var(--muted-text);
    font-size: var(--font-lg);
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    cursor: pointer;
    /* Below the overlay backdrop, which is fixed over the whole viewport
       at 2000. A dialog is modal, so everything outside it belongs behind
       it - and a button stacked above the backdrop is the one place where
       clicking while a dialog is open does nothing, which reads as the
       dialog being stuck. */
    z-index: 1100;
    box-shadow: var(--card-shadow);
}

.floating-info-button:hover {
    background: var(--panel-alt-bg);
}

/* ========================================
   FLOATING STACK BUTTONS
   Further round buttons rising above the info button, which keeps the
   corner. --stack-index says how many places above it a button sits, set
   by a modifier class rather than a style attribute, which the CSP of a
   vhost without 'unsafe-inline' would drop.
   Shown at every width, like the info button. A button that comes and goes
   is toggled through the hidden attribute and fades in on its way back.
   ======================================== */
.floating-stack-button {
    --stack-index: 1;
    /* One button plus the gap under the next one. */
    --floating-button-step: calc(var(--floating-button-size) + var(--space-small));

    position: fixed;
    right: var(--floating-button-offset);
    bottom: calc(var(--floating-button-offset)
                 + var(--stack-index) * var(--floating-button-step));
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--floating-button-size);
    height: var(--floating-button-size);
    padding: 0;
    border: 1px solid var(--frame-border);
    border-radius: 50%;
    background: var(--panel-bg);
    color: var(--muted-text);
    font-size: var(--font-lg);
    cursor: pointer;
    /* The info button's level, below the overlay backdrop for the same reason. */
    z-index: 1100;
    box-shadow: var(--card-shadow);
    animation: fadeIn var(--transition-slow) var(--ease-out) both;
}

.floating-stack-button--2 {
    --stack-index: 2;
}

.floating-stack-button--3 {
    --stack-index: 3;
}

.floating-stack-button:hover {
    background: var(--panel-alt-bg);
}

/* display: flex above would otherwise win over the hidden attribute. */
.floating-stack-button[hidden] {
    display: none;
}

/* ========================================
   ABOUT CONTENT
   The body of the about overlay: left-aligned prose inside a box whose other
   contents are centred, closed by the build line. The gaps come from the
   flex column - never from <br> tags.
   ======================================== */
.about-content {
    text-align: left;
    padding: var(--space-small);
    display: flex;
    flex-direction: column;
    gap: var(--space-medium);
}

.about-content p {
    font-size: var(--font-sm);
    text-align: left;
}

/* Indented, because the reset takes the list padding away and the markers
   would otherwise hang outside the text they number. */
.about-content ul,
.about-content ol {
    display: flex;
    flex-direction: column;
    gap: var(--space-small);
    padding-left: var(--space-large);
    font-size: var(--font-xs);
}

.version-info {
    margin-top: var(--space-medium);
    font-size: var(--font-xs);
    color: var(--muted-text);
    text-align: right;
}

/* ========================================
   FORMS
   A field is a label over its control; a row holds fields side by side and
   wraps on a narrow screen. Controls inside a field take its full width and
   16px text, below which a phone zooms the page on focus.
   ======================================== */
.field {
    display: flex;
    flex-direction: column;
    gap: var(--space-minimal);
    min-width: 0;
}

.field-label {
    color: var(--muted-text);
    font-size: var(--font-xs);
    letter-spacing: var(--letter-spacing-sm);
}

.field input:not([type="checkbox"]):not([type="radio"]),
.field select,
.field textarea {
    width: 100%;
    padding: var(--space-small);
    font-size: var(--font-base);
}

.field textarea {
    resize: vertical;
}

.field-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-small);
}

/* A field grows only inside a row; in a column it would stretch vertically. */
.field-row > .field {
    flex: 1 1 140px;
}

/* A checkbox and its words, the whole row clickable. */
.check {
    display: flex;
    align-items: center;
    gap: var(--space-small);
    font-size: var(--font-sm);
    cursor: pointer;
}

.check-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-medium);
}

/* A note under a field or a control - what to type, what it means. The same
   inside a dialog, where .floating-message p would otherwise make it the size
   of a notice. */
.hint,
.floating-message .hint {
    margin: 0;
    color: var(--muted-text);
    font-size: var(--font-xs);
}

/* Buttons of equal weight side by side, sharing the width. */
.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-small);
}

.button-row > button {
    flex: 1 1 140px;
}

/* ========================================
   NOTICES
   A line the page says about itself - a warning about the data, a failed
   login. It stays where it is put; the floating message is for what has to
   be read before going on.
   ======================================== */
.notice {
    padding: var(--space-small) var(--space-medium);
    border-radius: var(--radius-sm);
    background: var(--panel-alt-bg);
    color: var(--text-strong);
    font-size: var(--font-sm);
}

.notice--success {
    background: var(--badge-success-bg);
    color: var(--badge-success-text);
}

.notice--danger {
    background: var(--badge-danger-bg);
    color: var(--badge-danger-text);
}

.notice--warn {
    background: var(--badge-warn-bg);
    color: var(--badge-warn-text);
}

/* ========================================
   LOADING
   A wait the reader should see. The loading bar runs along an edge of
   whatever is being refilled, and placeholder bars stand where text is
   coming. Both repeat for as long as the wait lasts, the one exception to
   nothing repeating: a wait has no end the page knows of.

   The bar comes two ways with one look. `.loading-bar` is an element of
   its own, laid over a positioned box. `.loading-edge` draws it in the
   `::after` of the box itself while the box is `aria-busy`, for a box that
   cannot hold another child - one whose script empties it - or that should
   not need one. Either way the segment is painted in the background and
   moved by the background's position, so nothing has to clip it: it is the
   middle fifth of a background twice the bar's length, off the start at
   150% and off the end at -50%.
   ======================================== */
.loading-bar,
.loading-edge[aria-busy="true"]::after {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 2;
    height: var(--loading-bar-thickness);
    pointer-events: none;
    background:
        linear-gradient(90deg, transparent 40%, var(--accent-primary) 40% 60%, transparent 60%)
            0 0 / 200% 100% no-repeat,
        color-mix(in srgb, var(--accent-primary) 20%, transparent);
    animation: loadingSweep var(--loading-sweep) var(--ease-out) infinite;
}

.loading-bar[hidden] {
    display: none;
}

.loading-edge[aria-busy="true"]::after {
    content: "";
}

/* Positioned so the bar has an edge to run along, at no specificity: a
   box that is already positioned some other way keeps it. */
:where(.loading-edge) {
    position: relative;
}

/* Down the left edge, for something that stands up - a rail, a column. */
.loading-bar--vertical,
.loading-edge--vertical[aria-busy="true"]::after {
    right: auto;
    bottom: 0;
    width: var(--loading-bar-thickness);
    height: auto;
    background:
        linear-gradient(180deg, transparent 40%, var(--accent-primary) 40% 60%, transparent 60%)
            0 0 / 100% 200% no-repeat,
        color-mix(in srgb, var(--accent-primary) 20%, transparent);
    animation-name: loadingSweepDown;
}

/* In the flow instead of over a box: under a list whose next page is
   coming, where the reader is when it is asked for. */
.loading-bar--inline {
    position: relative;
    margin: var(--space-medium) 0;
}

@keyframes loadingSweep {
    from { background-position: 150% 0, 0 0; }
    to   { background-position: -50% 0, 0 0; }
}

@keyframes loadingSweepDown {
    from { background-position: 0 150%, 0 0; }
    to   { background-position: 0 -50%, 0 0; }
}

/* A line of text still on its way, as tall as the text it stands for. */
.placeholder-bar {
    display: block;
    width: 100%;
    height: 0.9em;
    border-radius: var(--radius-sm);
    /* The card border's grey: the panel greys are too close to a card's
       own background to show on it in the dark scheme. */
    background: linear-gradient(90deg,
        var(--card-border) 30%, var(--panel-bg) 50%, var(--card-border) 70%);
    background-size: 300% 100%;
    animation: placeholderSheen var(--loading-sweep) linear infinite;
}

.placeholder-bar--short {
    width: 55%;
}

.placeholder-bar--narrow {
    width: 30%;
}

@keyframes placeholderSheen {
    from { background-position: 100% 0; }
    to   { background-position: 0 0; }
}

/* Without motion both stand still and still say "not here yet", the bar's
   segment in its middle. Left to the block at the end of this file, each
   would run once and the segment would stop off the bar's end. */
@media (prefers-reduced-motion: reduce) {
    .loading-bar,
    .loading-edge[aria-busy="true"]::after,
    .placeholder-bar {
        animation: none;
    }

    .loading-bar,
    .loading-edge[aria-busy="true"]::after {
        background-position: 50% 0, 0 0;
    }

    .loading-bar--vertical,
    .loading-edge--vertical[aria-busy="true"]::after {
        background-position: 0 50%, 0 0;
    }
}

/* ========================================
   TILES
   Key figures side by side: a label, the value in the mono face, a note.
   The accent stripe marks the one figure the page is about.
   ======================================== */
.kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: var(--space-small);
}

.kpi {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    padding: var(--space-medium);
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-left: var(--border-strong) solid var(--panel-border);
    border-radius: var(--radius-md);
    box-shadow: var(--card-shadow);
}

.kpi--accent {
    border-left-color: var(--accent-primary);
}

.kpi-label {
    color: var(--muted-text);
    font-size: var(--font-xs);
    letter-spacing: var(--letter-spacing-sm);
    text-transform: uppercase;
}

.kpi-value {
    font-family: 'Roboto Mono', monospace;
    font-size: var(--font-lg);
    font-weight: 500;
    line-height: 1.2;
}

.kpi-note {
    color: var(--muted-text);
    font-size: var(--font-xs);
}

/* ========================================
   TABS AND SEGMENTED CONTROL
   The two button variants besides the pill and the danger button, for a
   choice among exclusive views - which one plain buttons cannot show. Tabs
   switch panels; a segmented control switches how one thing is shown. The
   current one is .is-active, set by setActive() with its ARIA state.
   ======================================== */
.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-minimal);
}

.tab {
    min-height: 44px;
    background-color: transparent;
    color: var(--muted-text);
    border: 1px solid transparent;
    transition: background-color var(--transition-fast) var(--ease-out),
                color var(--transition-fast) var(--ease-out);
}

.tab:hover {
    background-color: var(--accent-hover);
    color: var(--text-strong);
}

.tab.is-active {
    background-color: var(--card-bg);
    border-color: var(--card-border);
    color: var(--text-strong);
    font-weight: 500;
}

.segmented {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 1px;
    padding: 2px;
    background-color: var(--panel-alt-bg);
    border: 1px solid var(--frame-border);
    border-radius: var(--radius-sm);
}

.segmented-button {
    min-height: 32px;
    padding: var(--space-minimal) var(--space-small);
    background-color: transparent;
    color: var(--muted-text);
    border: 0;
    font-size: var(--font-sm);
    transition: background-color var(--transition-fast) var(--ease-out),
                color var(--transition-fast) var(--ease-out);
}

.segmented-button:hover {
    background-color: transparent;
    color: var(--text-strong);
}

.segmented-button.is-active {
    background-color: var(--card-bg);
    color: var(--text-strong);
    font-weight: 500;
}

/* ========================================
   CHART
   The canvas chart.js draws on, and the legend the page writes beside it - a
   div, since a dialog's paragraph rules would restyle a p.
   A legend entry is a button when it switches its series (wireLegend) and a
   span when it only names it; the swatch is its ::before, in the series'
   colour, a line or - for a band - a block.
   ======================================== */

.chart {
    display: block;
    width: 100%;
    height: var(--chart-height);
    /* Vertical swipes still scroll the page; horizontal ones select a stretch */
    touch-action: pan-y;
}

.chart--zoomable {
    cursor: crosshair;
}

.chart--zoomed {
    cursor: grab;
}

.chart--panning {
    cursor: grabbing;
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-small) var(--space-medium);
    color: var(--muted-text);
    font-size: var(--font-xs);
}

.legend {
    display: inline-flex;
    align-items: center;
    gap: var(--space-minimal);
}

/* After .floating-message button, which it ties with, so a legend in a dialog
   stays a legend */
button.legend {
    padding: 2px var(--space-minimal);
    background-color: transparent;
    border: 0;
    border-radius: var(--radius-sm);
    color: inherit;
    font-size: inherit;
    font-weight: inherit;
}

button.legend:hover {
    background-color: var(--accent-hover);
    color: var(--text-strong);
}

.legend.is-off {
    text-decoration: line-through;
    opacity: 0.5;
}

.legend::before {
    content: "";
    display: inline-block;
    width: 16px;
    height: 3px;
    border-radius: var(--radius-pill);
    background-color: var(--chart-1);
}

.legend--2::before { background-color: var(--chart-2); }
.legend--3::before { background-color: var(--chart-3); }
.legend--4::before { background-color: var(--chart-4); }

.legend--band::before {
    height: 10px;
    border-radius: 2px;
    opacity: 0.3;
}

/* ========================================
   ERROR PAGE
   A page that has nothing to show but why: the code, a sentence, the way
   back - centred under the page's usual header.
   ======================================== */
.error-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-medium);
    max-width: 520px;
    margin: var(--space-large) auto;
    text-align: center;
}

.error-code {
    font-family: 'Roboto Mono', monospace;
    font-size: var(--font-display);
    line-height: 1;
    color: var(--muted-text);
}

/* ========================================
   ACCOUNTS
   The login and registration card that
   login_form() and register_form() write:
   a narrow column of fields, centred
   under the page's usual header.
   ======================================== */
.auth-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-medium);
    max-width: 400px;
    margin: var(--space-large) auto;
}

.auth-card form {
    display: flex;
    flex-direction: column;
    gap: var(--space-medium);
}

/* The way to the other form, under the button. */
.auth-card .auth-switch {
    color: var(--muted-text);
    font-size: var(--font-sm);
}

/* ========================================
   UTILITY CLASSES
   ======================================== */
/* Secondary text in running prose - a unit, an aside. */
.muted {
    color: var(--muted-text);
}

/* Hidden visually, still read by screen readers. */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.loading {
    text-align: center;
    display: none;
}

/* ========================================
   SHARED KEYFRAMES
   Fires automatically when an element enters the DOM; no JS needed.
   ======================================== */
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ========================================
   HINT
   One ring of the accent around a control the reader should find - once,
   on arrival, never repeated (hintAt() in common.js takes it off again).
   ======================================== */
.is-hinted {
    animation: hint var(--transition-slow) var(--ease-out) both;
}

@keyframes hint {
    50% {
        box-shadow: 0 0 0 4px var(--accent-primary);
    }
}

/* ========================================
   REDUCED MOTION
   The one sanctioned use of !important.
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
