/*
 * Rhyme Dashboards: design tokens and styles.
 *
 * Every colour is defined once, as a token, for light and dark. The chart colours come from a palette
 * that was checked with the data-visualisation validator (colour-blind separation, contrast against the
 * surface); a test also checks the contrast of every text pairing below. Change a token, run the tests.
 *
 * Rules this file keeps (see docs/design/README.md):
 *  - text is always a text token; a data colour is only ever a mark (a line, a bar, a dot)
 *  - quiet chrome: hairline borders, no shadows, thin marks, generous space
 *  - status colours (good / bad / warning) mean state and are never used as series colours
 */

/* ---------- Tokens ---------- */

:root {
    color-scheme: light dark;

    /* surfaces and ink */
    --page: #f9f9f7;
    --surface: #fcfcfb;
    --text: #0b0b0b;
    --text-2: #52514e;
    --muted: #898781;            /* non-text only: icons, disabled borders. Too faint for text. */
    --grid: #e1e0d9;
    --baseline: #c3c2b7;
    --border: rgba(11, 11, 11, 0.12);
    --control-border: #898781;   /* edges of form controls must be visible: 3:1 */

    /* interaction */
    --accent: #256abf;           /* button background */
    --on-accent: #ffffff;        /* text on that background */
    --link: #1c5cab;
    --focus: #1c5cab;

    /* data (validated palette: slots 1 and 2, and the recessive comparison grey) */
    --series-1: #2a78d6;
    --series-2: #eb6834;
    --series-prev: #898781;

    /* state: each ships with an icon and words, never colour alone */
    --good: #006300;
    --bad: #d03b3b;
    --warning: #fab219;
    --warning-text: #6b4a00;

    /* scale */
    --radius: 12px;
    --radius-sm: 8px;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root:where(:not([data-theme="light"])) {
        --page: #0d0d0d;
        --surface: #1a1a19;
        --text: #ffffff;
        --text-2: #c3c2b7;
        --grid: #2c2c2a;
        --baseline: #383835;
        --border: rgba(255, 255, 255, 0.12);
        --control-border: #898781;
        --accent: #3987e5;
        --on-accent: #0b0b0b;
        --link: #86b6ef;
        --focus: #86b6ef;
        --series-1: #3987e5;
        --series-2: #d95926;
        --series-prev: #898781;
        --good: #0ca30c;
        --bad: #ec835a;
        --warning-text: #fab219;
    }
}

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

:root[data-theme="dark"] {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.12);
    --control-border: #898781;
    --accent: #3987e5;
    --on-accent: #0b0b0b;
    --link: #86b6ef;
    --focus: #86b6ef;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-prev: #898781;
    --good: #0ca30c;
    --bad: #ec835a;
    --warning-text: #fab219;
}

/* ---------- Base ---------- */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--page);
    color: var(--text);
    font: 400 1rem/1.5 var(--font);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

h1, h2, h3 {
    margin: 0;
    line-height: 1.25;
    font-weight: 600;
    color: var(--text);
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.125rem; }
h3 { font-size: 1rem; }

p { margin: 0 0 var(--space-3); }
small { color: var(--text-2); }
code { font: 0.875em ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--grid); padding: 0.1em 0.35em; border-radius: 4px; }

a { color: var(--link); text-underline-offset: 0.2em; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
    border-radius: 2px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    left: var(--space-4);
    top: -100px;
    background: var(--surface);
    color: var(--link);
    padding: var(--space-2) var(--space-4);
    border: 2px solid var(--focus);
    border-radius: var(--radius-sm);
    z-index: 10;
}
.skip-link:focus { top: var(--space-2); }

/* ---------- Page chrome ---------- */

.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.site-header__inner,
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding-inline: var(--space-4);
}

.site-header__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    min-height: 60px;
}

.brand { display: inline-flex; align-items: center; gap: var(--space-3); text-decoration: none; }
.brand img { display: block; height: 28px; width: auto; }
.brand--client img { height: 32px; width: auto; max-width: 160px; object-fit: contain; }
.brand__product { color: var(--text-2); font-size: 0.875rem; padding-left: var(--space-3); border-left: 1px solid var(--border); }

/* Navigation: links are real targets with a visible "you are here"; the account area sits apart, on the right. */
.site-nav { display: flex; align-items: stretch; align-self: stretch; gap: var(--space-5); font-size: 0.9375rem; }
.site-nav__links { display: flex; align-items: stretch; gap: var(--space-1); list-style: none; margin: 0; padding: 0; }
.site-nav__links li { display: flex; }
.site-nav__links a {
    display: flex;
    align-items: center;
    padding: 0 var(--space-3);
    color: var(--text-2);
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    border-bottom: 3px solid transparent;
}
.site-nav__links a:hover { color: var(--text); background: color-mix(in srgb, var(--text) 6%, transparent); }
.site-nav__links a[aria-current] { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }
.site-nav__links a:focus-visible { outline-offset: -3px; }   /* inside the box, so the header never clips it */

.site-nav__account { display: flex; align-self: center; align-items: center; gap: var(--space-3); padding-left: var(--space-5); border-left: 1px solid var(--border); }
.site-nav__user { color: var(--text-2); max-width: 18ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-nav__link-admin,
.site-nav__signout {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 0 var(--space-3);
    border: 1px solid var(--control-border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
}
.site-nav__link-admin:hover,
.site-nav__signout:hover { background: color-mix(in srgb, var(--text) 8%, transparent); }

/* The gear: opens the admin links in the strip under the header. */
.site-nav__gear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    align-self: center;
    width: 36px;
    height: 36px;
    margin-left: calc(var(--space-3) * -1);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
}
.site-nav__gear[hidden] { display: none; }
.site-nav__gear:hover { color: var(--text); background: color-mix(in srgb, var(--text) 8%, transparent); }
.site-nav__gear[aria-expanded="true"] { color: var(--text); border-color: var(--control-border); }
.site-nav__gear[data-section] { color: var(--accent); }

/* The admin strip: same look as the main links, one row beneath the header. */
.subnav { background: color-mix(in srgb, var(--text) 3%, var(--surface)); border-top: 1px solid var(--border); }
.subnav[hidden] { display: none; }
.subnav__inner { width: 100%; max-width: 1200px; margin: 0 auto; padding-inline: var(--space-4); }
.subnav__links { display: flex; flex-wrap: wrap; gap: var(--space-1); list-style: none; margin: 0; padding: 0; font-size: 0.9375rem; }
.subnav__links a {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 0 var(--space-3);
    color: var(--text-2);
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    border-bottom: 3px solid transparent;
}
.subnav__links a:hover { color: var(--text); background: color-mix(in srgb, var(--text) 6%, transparent); }
.subnav__links a[aria-current] { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }
.subnav__links a:focus-visible { outline-offset: -3px; }

@media (max-width: 720px) {
    .site-header__inner { flex-wrap: wrap; row-gap: 0; padding-top: var(--space-2); }
    .site-nav { width: 100%; justify-content: space-between; gap: var(--space-3); min-height: 44px; }
    .site-nav__account { padding-left: var(--space-3); }
    .site-nav__user { max-width: 12ch; }
}
@media (max-width: 480px) {
    .site-nav__user { display: none; }   /* the page itself says who is signed in where it matters; space goes to the links */
    .site-nav__account { padding-left: 0; border-left: 0; }
    .site-nav__links a { padding: 0 var(--space-2); }
}

/* The light / dark / auto switch. Hidden until its script has run. */
.theme-toggle {
    min-height: 36px;
    margin-left: var(--space-3);
    padding: 0 var(--space-3);
    border: 1px solid var(--control-border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text);
    font: 500 0.875rem/1 var(--font);
    cursor: pointer;
}
.theme-toggle[hidden] { display: none; }
.theme-toggle:hover { background: color-mix(in srgb, var(--text) 8%, transparent); }
/* Whatever comes second in the header (the navigation, or the switch when signed out) goes to the right edge. */
.site-header__inner > :nth-child(2) { margin-left: auto; }
@media (max-width: 720px) {
    /* Phone: logo and switch on the first row, navigation on the second. */
    .theme-toggle { order: 1; margin-left: auto; }
    .site-header__inner > .site-nav { order: 2; margin-left: 0; }
}

.site-main { flex: 1; width: 100%; }
.container { padding-block: var(--space-5) var(--space-6); }

.site-footer {
    border-top: 1px solid var(--border);
    color: var(--text-2);
    font-size: 0.875rem;
}
.site-footer__inner { display: flex; gap: var(--space-4); flex-wrap: wrap; justify-content: space-between; padding-block: var(--space-4); }
.site-footer p { margin: 0; }

/* The title and what explains it sit on the left; the button that makes a new thing (.page-head__actions) sits on the right,
   along the bottom of the head, nearest the first card. On a narrow screen it drops below. */
.page-head { margin-bottom: var(--space-5); display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: var(--space-5); align-items: start; grid-auto-flow: row dense; }
.page-head > * { grid-column: 1; }
.page-head > .crumbs { grid-column: 1 / -1; }
.page-head > .page-head__actions { grid-column: 2; grid-row: span 4; align-self: end; justify-self: end; display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
@media (max-width: 40rem) {
    .page-head { grid-template-columns: minmax(0, 1fr); }
    .page-head > .page-head__actions { grid-column: 1; grid-row: auto; justify-self: start; margin-top: var(--space-3); }
}
/* Breadcrumbs: quiet, so the page title leads; the current page is plain text. */
.crumbs { font-size: 0.875rem; margin-bottom: var(--space-2); }
.crumbs ol { display: flex; flex-wrap: wrap; align-items: center; list-style: none; margin: 0; padding: 0; }
.crumbs li + li::before { content: "\203A" / ""; color: var(--text-2); padding-inline: var(--space-2); }   /* a decorative separator */
.crumbs a { color: var(--text-2); text-decoration: none; padding-block: var(--space-1); }
.crumbs a:hover { color: var(--text); text-decoration: underline; }
.crumbs [aria-current] { color: var(--text); font-weight: 500; }

/* Tabs between a client's dashboards: buttons in a row. The current one is filled, the others are outlined. */
.tabs { margin-bottom: var(--space-4); }
.tabs ul { display: flex; flex-wrap: wrap; gap: var(--space-2); list-style: none; margin: 0; padding: 0; }
.tabs a {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    padding: 0 var(--space-4);
    border: 1px solid var(--control-border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-weight: 500;
    text-decoration: none;
}
.tabs a:hover { background: color-mix(in srgb, var(--text) 8%, transparent); }
.tabs a[aria-current] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.tabs a[aria-current]:hover { filter: brightness(1.08); background: var(--accent); }
.page-head p { color: var(--text-2); margin: var(--space-2) 0 0; max-width: 70ch; }

/* ---------- Components ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-4) var(--space-5);
}
.card > h2, .card > h3 { margin-bottom: var(--space-3); }

.stack > * + * { margin-top: var(--space-4); }
.plain-list { list-style: none; padding: 0; margin: 0; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 0 var(--space-4);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: var(--on-accent);
    font: 600 0.9375rem/1 var(--font);
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { filter: brightness(1.08); }
.btn--quiet { background: transparent; color: var(--link); border-color: var(--control-border); }

label { font-size: 0.875rem; font-weight: 600; color: var(--text-2); }

input, select, textarea {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--control-border);
    border-radius: var(--radius-sm);
    min-height: 40px;
    padding: 0 var(--space-3);
}
input:focus-visible, select:focus-visible { outline-offset: 0; }
/* Our own arrow, so it can sit well in from the right edge (the native one hugs it). The colour follows the theme. */
select:not([multiple]):not([size]) {
    appearance: none;
    padding-right: 2rem;
    text-overflow: ellipsis;
    background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
    background-position: calc(100% - 1.25rem) 50%, calc(100% - 0.9rem) 50%;
    background-size: 0.35rem 0.35rem, 0.35rem 0.35rem;
    background-repeat: no-repeat;
}

.field { display: flex; flex-direction: column; gap: var(--space-1); }

.notice {
    border: 1px solid var(--border);
    border-left-width: 4px;
    border-radius: var(--radius-sm);
    padding: var(--space-3) var(--space-4);
    background: var(--surface);
    font-size: 0.9375rem;
}
.notice p { margin: 0; }
.notice--warning { border-left-color: var(--warning); background: color-mix(in srgb, var(--warning) 12%, var(--surface)); }
.notice--warning strong, .notice--warning .notice__label { color: var(--warning-text); }
.notice--error { border-left-color: var(--bad); }
.notice--ok { border-left-color: var(--good); }

/* tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.9375rem; }
caption { text-align: left; color: var(--text-2); font-size: 0.875rem; padding-bottom: var(--space-2); }
th, td { padding: var(--space-2) var(--space-3); text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
thead th { color: var(--text-2); font-size: 0.8125rem; font-weight: 600; white-space: nowrap; }
tbody th { font-weight: 500; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tfoot th, tfoot td { border-bottom: 0; border-top: 2px solid var(--baseline); font-weight: 600; }

/* ---------- Forms (sign in, two-factor) ---------- */

.auth { max-width: 420px; margin: var(--space-6) auto; }
.auth h1 { margin-bottom: var(--space-4); }
.auth form { display: flex; flex-direction: column; gap: var(--space-4); }
.auth .btn { width: 100%; }
.auth__qr { display: block; margin: var(--space-4) auto; background: #fff; padding: var(--space-3); border-radius: var(--radius-sm); border: 1px solid var(--border); }
.auth code { word-break: break-all; }

/* ---------- Dashboard ---------- */

.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-3) var(--space-4);
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.filters__main { display: contents; }
.filters__custom { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-3); margin-left: auto; }

.dashboard-meta { color: var(--text-2); font-size: 0.9375rem; margin-bottom: var(--space-4); }
.dashboard-meta p { margin: 0 0 var(--space-1); }
.dashboard-notices { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-4); }

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: var(--space-4);
}
.widget {
    grid-column: span 12;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-4) var(--space-5);
    min-width: 0;   /* lets wide tables scroll inside the card instead of stretching the page */
}
.widget > h2 { margin-bottom: var(--space-3); font-size: 1rem; color: var(--text-2); font-weight: 600; }
.widget[data-width="3"] { grid-column: span 3; }
.widget[data-width="4"] { grid-column: span 4; }
.widget[data-width="6"] { grid-column: span 6; }
.widget[data-width="8"] { grid-column: span 8; }
.widget[data-width="9"] { grid-column: span 9; }
.widget[data-width="12"] { grid-column: span 12; }

@media (max-width: 960px) {
    .widget[data-width="3"], .widget[data-width="4"] { grid-column: span 6; }
    .widget[data-width="8"], .widget[data-width="9"] { grid-column: span 12; }
}
@media (max-width: 560px) {
    .widget[data-width] { grid-column: span 12; }
    .widget { padding: var(--space-4); }
    .filters__custom { margin-left: 0; }
}

.widget-message { color: var(--text-2); margin: 0; }
.widget[data-state="error"] { border-color: var(--bad); }

/* KPI tile: label, value, change, trend */
.kpi__value { font-size: 2rem; font-weight: 600; line-height: 1.1; margin: 0 0 var(--space-2); letter-spacing: -0.01em; }
.kpi__change { display: flex; align-items: baseline; gap: var(--space-2); margin: 0 0 var(--space-3); font-size: 0.875rem; color: var(--text-2); }
.kpi__delta { font-weight: 600; white-space: nowrap; }
.kpi__delta[data-verdict="better"] { color: var(--good); }
.kpi__delta[data-verdict="worse"] { color: var(--bad); }
.kpi__delta[data-verdict="neutral"],
.kpi__delta[data-verdict="flat"],
.kpi__delta[data-verdict="no_comparison"] { color: var(--text-2); }
.kpi__trend { display: block; width: 100%; height: 32px; overflow: visible; }
.kpi__trend polyline { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.kpi__trend circle { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }

/* charts */
.chart { margin: 0; }
.chart + .chart { margin-top: var(--space-5); }
.chart__title { font-size: 0.9375rem; font-weight: 600; color: var(--text); margin-bottom: var(--space-2); }
.chart__legend { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-4); margin: 0 0 var(--space-3); padding: 0; list-style: none; font-size: 0.875rem; color: var(--text-2); }
.chart__legend li { display: inline-flex; align-items: center; gap: var(--space-2); }
.chart__key { display: inline-block; width: 18px; height: 0; border-top: 2px solid; border-radius: 2px; }   /* a short line, not a box */
.chart__canvas { position: relative; height: 240px; }
.chart__canvas canvas { display: block; width: 100%; height: 100%; touch-action: pan-y; }
.chart__tooltip {
    position: absolute;
    z-index: 2;
    pointer-events: none;
    min-width: 150px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    padding: var(--space-2) var(--space-3);
    font-size: 0.8125rem;
}
.chart__tooltip[hidden] { display: none; }
.chart__tooltip-title { color: var(--text-2); margin-bottom: var(--space-1); }
.chart__tooltip-row { display: flex; align-items: center; gap: var(--space-2); }
.chart__tooltip-value { font-weight: 600; font-variant-numeric: tabular-nums; }   /* the value leads... */
.chart__tooltip-name { color: var(--text-2); }                                     /* ...the name follows */
.chart__toggle { margin-top: var(--space-3); }
.chart__data { margin-top: var(--space-3); }
.chart.is-enhanced .chart__data[hidden] { display: none; }
.chart:not(.is-enhanced) .chart__canvas,
.chart:not(.is-enhanced) .chart__toggle { display: none; }   /* no script: the table is the chart */

/* ranked table */
.ranked td.num, .ranked th.num { min-width: 5.5rem; }
.ranked tbody th { max-width: 22rem; overflow-wrap: anywhere; }
.platform-tag { color: var(--text-2); font-size: 0.8125rem; white-space: nowrap; }

/* long-form text (privacy policy) */
.prose { max-width: 72ch; }
.prose h2 { margin: var(--space-5) 0 var(--space-2); }
.prose h3 { margin: var(--space-4) 0 var(--space-2); color: var(--text-2); }
.prose ul, .prose ol { padding-left: 1.4em; margin: 0 0 var(--space-3); }
.prose li { margin-bottom: var(--space-1); }
.prose address { font-style: normal; }

/* ---------- Print: a client may print or save a dashboard ---------- */

@media print {
    :root { color-scheme: light; }
    body { background: #fff; color: #000; display: block; }
    .site-header__inner { padding-block: 0 8px; }
    .site-nav, .subnav, .section-nav, .theme-toggle, .tabs, .crumbs, .brand__product, .site-footer a, .filters, .skip-link, .chart__toggle, .btn { display: none !important; }
    .site-header, .site-footer { border: 0; }   /* the client's logo and footer line still print */
    .container { max-width: none; padding: 0; }
    .widget { break-inside: avoid; border-color: #bbb; }
    .dashboard-grid { gap: 8px; }
    a { color: inherit; text-decoration: none; }
    .chart.is-enhanced .chart__data[hidden] { display: block; }   /* print the numbers too */
}

/* ---------- Forced colours (Windows high contrast) ---------- */

@media (forced-colors: active) {
    .widget, .card, .filters, .notice { border: 1px solid CanvasText; }
    .kpi__trend polyline { stroke: CanvasText; }
    .kpi__trend circle { fill: CanvasText; stroke: Canvas; }
    .btn { border-color: ButtonText; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}

/* ---------- Dashboard builder (staff) ---------- */

.form-grid { display: grid; gap: var(--space-4); max-width: 640px; }
.help { color: var(--text-2); font-size: 0.8125rem; }
.fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--space-3) var(--space-4); display: grid; gap: var(--space-3); }
.fieldset legend { font-size: 0.875rem; font-weight: 600; color: var(--text-2); padding: 0 var(--space-1); }
.field--check label { display: flex; align-items: center; gap: var(--space-2); font-weight: 500; color: var(--text); }
.field--check input { min-height: 0; width: 1.125rem; height: 1.125rem; }
.actions { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-2) var(--space-4); }
.row__actions { display: flex; gap: var(--space-4); }
.row-list { display: flex; flex-wrap: wrap; gap: var(--space-3); }
/* Meaning is in the words ("Delete", "Remove"); the border only reinforces it, and text keeps its own colour. */
.btn--danger { background: transparent; color: var(--text); border: 2px solid var(--bad); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; filter: none; }
.widget-list { list-style: none; margin: 0 0 var(--space-5); padding: 0; display: grid; gap: var(--space-3); }
.widget-list__item { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-3) var(--space-5); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--space-3) var(--space-4); }
.widget-list__item:target { outline: 2px solid var(--focus); }
.widget-list__main { flex: 1 1 280px; min-width: 0; }
.widget-list__title { margin: 0 0 var(--space-2); }
.widget-list__actions { display: flex; flex-wrap: nowrap; gap: var(--space-1); align-items: center; align-self: flex-start; }
/* Beats ".card form + form" (which adds space above a second form), so the icons share one line. */
.card .widget-list__actions form { margin: 0; display: flex; }
.settings-list { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-5); margin: 0; font-size: 0.875rem; }
.settings-list dt { display: inline; color: var(--text-2); }
.settings-list dt::after { content: ': '; }
.settings-list dd { display: inline; margin: 0; }
@media print { .widget-list__actions { display: none; } }

/* ---------- Branding screen (staff) ---------- */

.logo-preview { background: repeating-conic-gradient(var(--grid) 0% 25%, var(--surface) 0% 50%) 50% / 16px 16px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--space-3); display: inline-block; max-width: 100%; }
.logo-preview img { display: block; max-width: 100%; height: auto; }
.swatches { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--space-3); }
.swatch { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--space-4); }
.swatch__button { display: inline-block; padding: 8px 16px; border-radius: var(--radius-sm); font-weight: 600; margin-right: var(--space-4); }
.swatch__link { text-decoration: underline; font-weight: 600; }
.swatch__codes { margin: var(--space-3) 0 0; font-size: 0.8125rem; }

/* The sections of one client (Overview, Reports and dashboards, Branding): the main navigation's look, one level down. */
.section-nav { margin: calc(var(--space-2) * -1) 0 var(--space-5); border-bottom: 1px solid var(--border); }
.section-nav ul { display: flex; flex-wrap: wrap; gap: var(--space-1); list-style: none; margin: 0; padding: 0; }
.section-nav a {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 0 var(--space-3);
    color: var(--text-2);
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    border-bottom: 3px solid transparent;
    margin-bottom: -1px;   /* the bar sits on the line under the whole row */
}
.section-nav a:hover { color: var(--text); background: color-mix(in srgb, var(--text) 6%, transparent); }
.section-nav a[aria-current] { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }
.section-nav a:focus-visible { outline-offset: -3px; }

/* Lists of things to open, shown as buttons or rows rather than bare links. */
.button-list { display: flex; flex-wrap: wrap; gap: var(--space-3); list-style: none; margin: 0 0 var(--space-4); padding: 0; }
.btn--sm { min-height: 32px; padding: 0 var(--space-3); font-size: 0.875rem; }
.row-links { list-style: none; margin: 0; padding: 0; }
.row-links li { display: flex; align-items: center; border-bottom: 1px solid var(--border); }
.row-links li:last-child { border-bottom: 0; }
.row-links a { flex: 1; display: flex; align-items: center; justify-content: space-between; min-height: 48px; padding: 0 var(--space-3); color: var(--text); font-weight: 500; text-decoration: none; border-radius: var(--radius-sm); }
.row-links a::after { content: "\203A" / ""; color: var(--text-2); font-size: 1.25rem; }
.row-links a:hover { background: color-mix(in srgb, var(--text) 6%, transparent); }
.row-links small { color: var(--text-2); margin-right: var(--space-3); }

/* ---------- Written summary and highlight widgets ---------- */

.summary__period { margin: 0 0 var(--space-1); color: var(--text-2); font-size: 0.875rem; }
.summary__date { color: var(--text-2); }
.summary__headline { display: block; margin: 0 0 var(--space-4); font-size: 1.25rem; font-weight: 600; line-height: 1.35; color: var(--text); }
.summary__section + .summary__section { margin-top: var(--space-4); }
.summary__section h4 { margin: 0 0 var(--space-1); font-size: 1rem; font-weight: 600; color: var(--text); }
.summary__section p { margin: 0 0 var(--space-2); max-width: 75ch; color: var(--text-2); }   /* body text a step softer than the headline and titles, so they stand out */
.highlight__note { margin: var(--space-1) 0 0; }
.highlight__source { margin: var(--space-2) 0 0; color: var(--text-2); font-size: 0.8125rem; }
.link-field { width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.875rem; }
.summary-form { max-width: 820px; }
.summary-form textarea { min-height: 8rem; padding: var(--space-2) var(--space-3); line-height: 1.5; resize: vertical; }

/* Step-by-step setup guides and the plain facts list on a connection */
.steps { list-style: none; counter-reset: step; padding: 0; margin: 0; display: grid; gap: 20px; }
.steps > li { counter-increment: step; position: relative; padding-left: 44px; }
.steps > li::before { content: counter(step); position: absolute; left: 0; top: 0; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; background: var(--surface-2, var(--surface)); border: 2px solid var(--border, currentColor); }
.steps h3 { margin: 0 0 6px; font-size: 1.05rem; }
.steps ol { padding-left: 20px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 20px; margin: 0 0 12px; }
.facts dt { font-weight: 600; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
textarea[data-support-details] { width: 100%; font-family: ui-monospace, monospace; font-size: 0.9rem; }
@media (max-width: 40rem) { .facts { grid-template-columns: 1fr; } }
.muted { color: var(--text-muted, inherit); opacity: 0.8; }

/* Filters and other small forms: every control on one line once there is room, wrapping only when there is not. */
.form-inline { display: flex; flex-wrap: wrap; gap: var(--space-3) var(--space-4); align-items: flex-end; }
.form-inline > .field { flex: 1 1 11rem; max-width: 22rem; }
.form-inline > .actions { flex: 0 0 auto; }
.inline-form { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-3); align-items: center; }
.inline-form small { color: var(--text-2); }
.card form + form, .card .inline-form + .inline-form, .card .form-inline + .inline-form { margin-top: var(--space-3); }
/* A row of buttons, such as the platforms to add a connection for. */
.button-list > li { display: flex; }
.list-gap > li + li { margin-top: var(--space-2); }

/* Notifications: the add form and the two actions share one row once there is room. */
.notification-controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-3) var(--space-4); }
.notification-controls > form { margin-top: 0; }
.notification-controls__add { flex: 1 1 24rem; }
.notification-controls__add > .field { max-width: none; flex: 1 1 14rem; }

/* On / off indicator: a small orb that pulses, green when on and red when off. The word carries the meaning too. */
.status { display: inline-flex; align-items: center; gap: var(--space-2); margin-left: var(--space-2); font-size: 0.875rem; font-weight: 600; vertical-align: middle; }
.status--on { color: var(--good); }
.status--off { color: var(--bad); }
.status__orb { position: relative; width: 0.625rem; height: 0.625rem; border-radius: 50%; background: currentColor; }
.status__orb::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: currentColor; animation: status-pulse 2s ease-out infinite; }
@keyframes status-pulse { from { transform: scale(1); opacity: 0.6; } to { transform: scale(2.6); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .status__orb::after { animation: none; } }

/* A list of things with a short description under each name (reports, dashboards). */
.summary-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-3); }
.summary-list__item { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2) var(--space-5); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--space-3) var(--space-4); }
.summary-list__main { flex: 1 1 18rem; min-width: 0; }
.summary-list__title { margin: 0; }
.summary-list__summary { margin: var(--space-1) 0 0; color: var(--text-2); font-size: 0.9375rem; }

/* Icon buttons for the actions on a row. The tooltip shows on hover and on keyboard focus. */
.icon-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--control-border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
    text-decoration: none;
}
.icon-btn:hover { color: var(--text); background: color-mix(in srgb, var(--text) 8%, transparent); }
.icon-btn--danger { color: var(--bad); }
.icon-btn--danger:hover { color: var(--bad); border-color: var(--bad); }
.icon-btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.icon-btn[disabled]:hover { background: transparent; color: var(--text-2); }
.icon-btn[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    right: 0;
    z-index: 5;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    background: var(--text);
    color: var(--surface);
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.3;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transform: translateY(2px);
    transition: opacity 0.12s ease, transform 0.12s ease;
}
.icon-btn[data-tooltip]:hover::after,
.icon-btn[data-tooltip]:focus-visible::after { opacity: 1; transform: none; }
@media print { .icon-btn { display: none; } }

/* ---------- Toasts and invalid fields ---------- */

/* Without JavaScript a toast is an ordinary notice in the page; with it, it floats over the page so nothing moves. */
.toast-region { display: grid; gap: var(--space-2); margin-bottom: var(--space-4); }
.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--border);
    border-left-width: 4px;
    border-radius: var(--radius-sm);
    background: var(--surface);
}
.toast--ok { border-left-color: var(--good); }
.toast--error { border-left-color: var(--bad); }
.toast__body { flex: 1; min-width: 0; }
.toast__body p, p.toast__body { margin: 0; }
.toast__body ul { margin: var(--space-1) 0 0; padding-left: var(--space-5); }
.toast__close {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    margin: -4px -8px 0 0;
    padding: 0;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
}
.toast__close[hidden] { display: none; }
.toast__close:hover { color: var(--text); background: color-mix(in srgb, var(--text) 8%, transparent); }

html.js .toast-region {
    position: fixed;
    top: var(--space-4);
    right: var(--space-4);
    z-index: 30;
    width: min(26rem, calc(100vw - 2 * var(--space-4)));
    margin: 0;
    pointer-events: none;
}
html.js .toast {
    pointer-events: auto;
    box-shadow: 0 6px 24px color-mix(in srgb, #000 22%, transparent);
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity 0.18s ease, transform 0.18s ease;
}
html.js .toast--shown { opacity: 1; transform: none; }
@media (max-width: 560px) {
    html.js .toast-region { top: auto; bottom: var(--space-3); right: var(--space-3); left: var(--space-3); width: auto; }
}
@media print { .toast-region { display: none; } }

/* A field that is at fault: a red border that does not rely on colour alone (a heavier line), and its label turns red. */
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"],
input:user-invalid, select:user-invalid, textarea:user-invalid {
    border-color: var(--bad);
    box-shadow: 0 0 0 1px var(--bad);
}
.field--error > label { color: var(--bad); }

/* ---------- PDF documents (drawn by headless Chromium from /internal/print) ---------- */

@page { size: A4; margin: 14mm 12mm 16mm; @bottom-right { content: counter(page) " / " counter(pages); font: 9pt/1 sans-serif; color: #666; } }
.print-doc { background: #fff; color: #1a1a1a; }
.print-doc__cover { padding-bottom: var(--space-4); margin-bottom: var(--space-5); border-bottom: 2px solid var(--accent); }
.print-doc__logo { display: block; max-height: 48px; max-width: 220px; width: auto; margin-bottom: var(--space-4); }
.print-doc__cover h1 { margin: 0 0 var(--space-1); }
.print-doc__cover p { margin: 0 0 var(--space-1); color: #444; }
.print-doc__page { break-before: page; }
.print-doc__page:first-of-type { break-before: avoid; }
.print-doc__tab { margin: 0 0 var(--space-4); padding-bottom: var(--space-2); border-bottom: 1px solid var(--border); }
.print-doc .widget { break-inside: avoid; }
.print-doc .chart__toggle { display: none; }
.print-doc .chart.is-enhanced .chart__data[hidden] { display: none; }   /* the PDF shows the chart; the day-by-day table stays in the CSV */
.print-doc .widget:has(table) { grid-column: 1 / -1; }   /* a table needs the whole width of the page */
