/* Site chrome for server-rendered pages — built entirely on tokens.css
 * custom properties. Page-specific stylesheets (e.g. the dashboard island's
 * dashboard.css) layer on top of this, not instead of it.
 *
 * Layout: an app shell — persistent sidebar (collapses to a drawer under
 * 880px) + slim top bar + scrolling content column. Anonymous pages
 * (login/register/invite links) get the same top bar without the sidebar. */

/* Space Grotesk, self-hosted rather than CDN-loaded — same convention as the
 * vendored esp-web-tools/esptool-js/CodeMirror bundles. One variable-weight
 * file per subset covers 400-700, so there is no per-weight request fan-out.
 * Paths are relative to this file (static/css/), which survives collectstatic
 * unchanged; a Django {% static %} tag can't be used inside a plain .css file.
 * See static/fonts/NOTICE.md for licensing. */
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("../fonts/space-grotesk-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6,
    U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122,
    U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("../fonts/space-grotesk-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7,
    U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F,
    U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F,
    U+A720-A7FF;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
}

a {
  color: var(--color-primary);
}

/* ================= Display typography ================= */

/* Headings carry the brand voice; body copy stays on the system stack. Set
 * once here so any heading anywhere picks it up without a per-page rule. */
h1,
h2,
h3,
.display {
  font-family: var(--font-display);
  line-height: var(--line-height-display);
  letter-spacing: var(--letter-spacing-display);
  text-wrap: balance;
}

h1 {
  font-size: var(--font-size-h1);
  font-weight: 700;
}

h2 {
  font-size: var(--font-size-h2);
  font-weight: 650;
}

h3 {
  font-size: var(--font-size-h3);
  font-weight: 650;
}

/* ================= App shell ================= */

.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 30;
}

.brand {
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--color-border);
}

.brand-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
  color: var(--color-text);
}

.brand-mark {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  flex: none;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: 0.005em;
}

.nav {
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-section {
  font-size: 0.6875rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--color-muted);
  padding: var(--space-4) var(--space-3) var(--space-1);
}

/* The nav now opens with a section label ("Monitor") rather than a link, and
 * the rule above adds a full space-4 above every label to separate it from the
 * group before it — which there isn't one of, at the top. */
.nav-section:first-child {
  padding-top: var(--space-2);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: 6px;
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: var(--font-size-sm);
  font-weight: 500;
  border-left: 2px solid transparent;
}

.nav-link svg {
  flex: none;
  opacity: 0.85;
}

.nav-link:hover {
  background: var(--accent-wash);
  color: var(--color-text);
}

.nav-link.active {
  background: var(--accent-wash);
  color: var(--color-primary);
  border-left-color: var(--color-primary);
}

.sidebar-foot {
  border-top: 1px solid var(--color-border);
  padding: var(--space-3) var(--space-6);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--font-size-sm);
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-wash);
  color: var(--color-primary);
  display: grid;
  place-items: center;
  font-weight: 650;
  font-size: 0.75rem;
  flex: none;
}

.sidebar-foot .who {
  min-width: 0;
}

.sidebar-foot .who-name {
  display: block;
  font-weight: 550;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-foot .who-meta {
  color: var(--color-text-muted);
  font-size: 0.75rem;
}

.sidebar-foot .who-meta form {
  display: inline;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: 56px;
  padding: 0 var(--space-6);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

/* The page's <h1>. On desktop the sidebar's active nav item already says where
 * you are, so showing it here too was a visible duplicate of the page heading
 * directly below it. It is only *visually* hidden there, never `display: none`
 * — it stays the document's h1 in the accessibility tree, and it becomes
 * visible again under 880px where the sidebar collapses into a drawer and this
 * is the only remaining location cue. */
.topbar-title {
  font-family: var(--font-display);
  font-size: var(--font-size-base);
  font-weight: 650;
  margin: 0;
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.topbar-spacer {
  flex: 1;
}

.topbar-links {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  font-size: var(--font-size-sm);
}

/* The anonymous topbar carries the brand, the theme toggle and two auth
 * buttons. `.topbar` is otherwise a fixed-height, no-wrap row, which would
 * push the page sideways once those buttons don't fit — scoped to the
 * anonymous shell so the authenticated topbar keeps its exact 56px row. */
.shell-anonymous .topbar {
  flex-wrap: wrap;
  height: auto;
  min-height: 56px;
  row-gap: var(--space-2);
  padding-block: var(--space-2);
}

/* ---- Per-page topbar controls (refresh + auto-refresh) ----
 * Rendered into base.html's {% block topbar_extra %}: by
 * partials/refresh_controls.html on the server-rendered pages, and by
 * DashboardApp.jsx's createPortal on the dashboard. Both share these rules so
 * the pair looks identical wherever it appears — the dashboard's copy used to
 * live in frontend/src/styles.css, which no other page loads. */
.topbar-page-controls {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.refresh-interval-select {
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
  cursor: pointer;
}

.refresh-btn {
  border: 1px solid var(--color-border);
}

.refresh-btn:disabled {
  cursor: default;
  opacity: 0.6;
}

/* Only the glyph spins, never the button: rotating the element itself takes
 * its border box round with it, so the control reads as tumbling rather than
 * as an icon turning inside a button that is standing still. The icon is
 * drawn centred on its own viewBox (circle centre 8,8 in a 16x16 box) so the
 * default `transform-origin: 50% 50%` spins it true, with no wobble. */
.refresh-btn-spinning .refresh-icon {
  animation: refresh-spin 0.7s linear infinite;
}

@keyframes refresh-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* `.topbar` is otherwise a fixed-height, no-wrap 56px row — fine for the
 * stock hamburger/title/theme-toggle, but these controls no longer fit
 * alongside them at phone widths and would push the whole page sideways.
 * Scoped with :has() so only a page that actually injects controls wraps;
 * every other authenticated page keeps its exact 56px row. */
@media (max-width: 640px) {
  .topbar:has(.topbar-page-controls) {
    flex-wrap: wrap;
    height: auto;
    min-height: 56px;
    row-gap: var(--space-2);
  }

  .topbar:has(.topbar-page-controls) .topbar-title {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-page-controls {
    order: 1;
    flex-basis: 100%;
    justify-content: flex-end;
  }
}

/* ---- Theme toggle ----
 * Both icons are in the markup; exactly one is shown per theme, so the button
 * is right from first paint. Show the moon in light mode and the sun in dark:
 * the icon previews what you'd switch *to*, matching the aria-label
 * shell.js keeps in sync. */
.theme-icon {
  display: none;
}

:root[data-theme="dark"] .theme-icon-sun {
  display: block;
}

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

.icon-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: var(--space-1);
  cursor: pointer;
  color: var(--color-text-muted);
  display: grid;
  place-items: center;
  font-size: var(--font-size-base);
  line-height: 1;
}

.icon-btn:hover {
  background: var(--accent-wash);
  color: var(--color-text);
}

#hamburger {
  display: none;
}

#backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 25;
}

.content {
  padding: var(--space-6);
  max-width: 1160px;
  width: 100%;
  margin: 0 auto;
}

.shell-anonymous .content {
  max-width: 960px;
}

.page-intro {
  margin: 0 0 var(--space-6);
}

.page-intro h2 {
  margin: 0 0 var(--space-1);
  font-size: var(--font-size-h1);
  font-weight: 700;
}

.page-intro p {
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  max-width: 68ch;
}

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ================= Cards, forms, buttons (pre-shell classes) ============ */

/* A card reads as a raised surface, not a boxed outline — the hairline border
 * stays (it's what separates a white card from a white-ish page background in
 * light mode) but the shadow now does most of the lifting. */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
}

.card-narrow {
  max-width: 360px;
  width: 100%;
}

/* Multi-field forms need more room than the 360px login-box width, but still
 * shouldn't run to the full content width — long input lines are hard to scan. */
.card-form {
  max-width: 760px;
  width: 100%;
}

/* Only for pages where the card *is* the whole page (login, register...) —
 * centers it in the viewport. Pages with a heading/breadcrumb above the card
 * must NOT use this, or the card drifts out of alignment with them. */
.card-centered {
  margin: 0 auto;
}

.card-head {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  margin: 0 0 var(--space-4);
}

.card-head h3 {
  margin: 0;
  font-size: var(--font-size-sm);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.card-head h3 svg {
  flex: none;
  color: var(--color-text-muted);
}

.card-head .sub {
  color: var(--color-text-muted);
  font-size: 0.75rem;
}

.card-head .link {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: auto;
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-primary);
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s ease;
}

.card-head .link:hover {
  background: var(--accent-wash);
}

.card-head .link svg {
  flex: none;
  transition: transform 0.15s ease;
}

.card-head .link:hover svg {
  transform: translateX(2px);
}

.form-field {
  margin-bottom: var(--space-4);
}

.form-field label {
  display: block;
  margin-bottom: var(--space-1);
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-base);
  font-family: inherit;
  background: var(--color-surface);
  color: var(--color-text);
}

/* Inputs previously fell back to the browser's default focus ring, which
 * doesn't match the navy ring every link and button uses. */
.form-field input:focus-visible,
.form-field select:focus-visible,
.form-field textarea:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
  border-color: var(--color-primary);
}

/* Sketch-source entry (device firmware authoring) and the read-only starter
 * template preview above it — same monospace stack as .cell-mono. */
.code-textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  tab-size: 2;
}

.code-block {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.75rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: var(--space-2) 0;
}

.form-field small {
  display: block;
  margin-top: var(--space-1);
  color: var(--color-text-muted);
  font-size: 0.75rem;
  line-height: 1.45;
}

/* `.form-field small { display: block }` above has higher specificity than
 * the browser's default `[hidden] { display: none }` UA rule, so a `<small
 * hidden>` inside a .form-field (e.g. detect-mac-status/-unsupported) would
 * otherwise stay visible despite the attribute. */
.form-field small[hidden] {
  display: none;
}

/* A standalone explanation belonging to the control directly above it, where
 * the text changes with that control's value and so can't live in a field's
 * static help_text (e.g. which board the chosen firmware will compile for).
 * Styled to match `.form-field small` so it reads as that field's help text
 * despite sitting outside the .form-field wrapper; the negative top margin
 * pulls it back under the control it describes. */
.form-note {
  margin: calc(var(--space-2) * -1) 0 var(--space-4);
  color: var(--color-text-muted);
  font-size: 0.75rem;
  line-height: 1.45;
}

.form-note strong {
  color: var(--color-text);
  font-weight: 600;
}

/* Belt and braces: a <p> would honour [hidden] on its own, but every other
 * hideable element on this page needed an explicit rule (see the note above
 * on .form-field small), and JS toggles this one by release. */
.form-note[hidden] {
  display: none;
}

/* An input sharing its row with a button (e.g. mac_address's "Detect via
 * USB") — .form-field's own `input { width: 100% }` would otherwise push
 * the button onto its own line. */
.field-with-action {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

.field-with-action input {
  flex: 1;
  width: auto;
  min-width: 0;
}

.field-with-action .button {
  flex: none;
}

/* Multi-field forms (parser rules, device types...) — groups related fields
 * under a heading and lays short ones two-up, instead of one long single
 * column. `.form-grid` is the row container; a field opts out of the two-up
 * split with `.form-field-wide` (topic patterns, anything with long help). */
.form-section {
  border: 0;
  padding: 0;
  margin: 0 0 var(--space-6);
  min-width: 0;
}

.form-section:last-of-type {
  margin-bottom: var(--space-4);
}

.form-section > legend {
  padding: 0;
  margin-bottom: var(--space-3);
  font-size: 0.6875rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 var(--space-6);
  align-items: start;
}

.form-field-wide {
  grid-column: 1 / -1;
}

/* Checkboxes must not inherit the width:100% meant for text inputs, and read
 * better with the label beside the box rather than stacked above it. */
.form-check-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.form-check-row input[type="checkbox"] {
  width: auto;
  margin: 0;
  flex: none;
}

.form-check-row label {
  margin: 0;
  color: var(--color-text);
}

/* Radio groups hit exactly the same trap as checkboxes above: Django renders a
 * RadioSelect as bare <input type="radio"> elements inside .form-field, which
 * would inherit the width:100% meant for text inputs and draw each one as a
 * full-width bordered box. Each option's label also needs to sit beside its
 * button rather than above it, and options need to stack. */
/* Django wraps each option as <label><input> text</label>, so the label is the
 * flex container and the input is its first child. Deliberately scoped to a
 * wrapper that renders NO field label of its own (the question goes in a
 * <legend>) — otherwise this rule would also flatten that label's weight. */
.form-radio-group label {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  margin: 0 0 var(--space-2) 0;
  font-weight: 400;
  color: var(--color-text);
}

.form-radio-group input[type="radio"] {
  width: auto;
  margin: 0;
  flex: none;
  /* Nudge down so it aligns with the first line of a label that wraps to two. */
  margin-top: 0.25em;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}

/* The primary call-to-action. Orange, not navy: navy is the site's ambient
 * link/nav color and a navy button never stood out from it. --color-accent-
 * strong (not --color-accent) is the fill, because the vivid brand orange
 * can't carry white text at AA — see tokens.css. */
.button {
  display: inline-block;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-accent-strong);
  background: var(--color-accent-strong);
  color: var(--color-accent-strong-text);
  font-size: var(--font-size-base);
  font-weight: 550;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.button:hover {
  background: color-mix(in srgb, var(--color-accent-strong) 88%, black);
  border-color: color-mix(in srgb, var(--color-accent-strong) 88%, black);
}

/* `.button[hidden]` needs its own rule: `.button`'s `display: inline-block`
 * above has the same specificity as the browser's default `[hidden] {
 * display: none }` UA rule, and an equal-specificity author rule always
 * wins over the UA stylesheet — so a `hidden` .button (e.g. detect-mac-button
 * before JS feature-detection reveals it) would otherwise stay visible. */
.button[hidden] {
  display: none;
}

.button-secondary {
  background: transparent;
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.button-secondary:hover {
  background: var(--accent-wash);
  border-color: var(--color-primary);
}

/* Destructive confirmations ("Yes, delete"). These used the plain .button
 * class, which now means "the orange thing you probably want to press" — the
 * opposite of the intent, and orange is also the wrong signal for a
 * destructive step. Red fill, per-theme text token (see tokens.css). */
.button-danger {
  border-color: var(--color-danger);
  background: var(--color-danger);
  color: var(--color-danger-text);
}

.button-danger:hover {
  background: color-mix(in srgb, var(--color-danger) 88%, black);
  border-color: color-mix(in srgb, var(--color-danger) 88%, black);
}

/* Compact size for the topbar — full-size padding makes a 56px row look
 * stuffed. Must stay *after* `.button`: the two selectors have identical
 * specificity, so whichever is declared last wins, and placing this earlier
 * silently gave the "small" button the full-size padding. */
.button-sm {
  padding: var(--space-1) var(--space-3);
  font-size: var(--font-size-sm);
  line-height: 1.6;
  white-space: nowrap;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

@media (prefers-reduced-motion: reduce) {
  .button {
    transition: none;
  }
}

/* Generic "in flight" state applied by shell.js to whichever button actually
 * submitted a plain (non-AJAX) form — see shell.js for why this has to be
 * CSS-only feedback rather than swapped button text: with dozens of forms
 * across the site all carrying different labels ("Save", "Create device
 * type", "Add metric"...), there's no one string to swap in generically.
 * The ring uses `currentColor` (not a token) deliberately, so it inherits
 * whatever text color the specific button variant already has — `.button`'s
 * light text on a solid orange fill, `.button-secondary`'s navy text on
 * transparent, `.button-danger`'s text on red — and needs no per-variant
 * override to stay legible in either theme. */
.button.is-loading {
  position: relative;
  padding-left: calc(var(--space-4) + 1.2em);
}

.button.is-loading::before {
  content: "";
  position: absolute;
  left: var(--space-3);
  top: 50%;
  width: 0.9em;
  height: 0.9em;
  margin-top: -0.45em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-bottom-color: transparent;
  border-radius: 50%;
  animation: button-spinner-spin 0.6s linear infinite;
}

@keyframes button-spinner-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .button.is-loading::before {
    animation: none;
  }
}

.error-list {
  color: var(--color-danger);
  font-size: var(--font-size-sm);
  padding-left: var(--space-4);
  margin: 0 0 var(--space-4);
}

.link-button {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--color-primary);
  cursor: pointer;
}

/* An inline link inside a sentence ("No account yet? Register"). It keeps the
 * underline on purpose — a link in running prose shouldn't be distinguishable
 * by color alone — but softens and offsets it so it reads as designed rather
 * than as the browser default it used to be. Anything link-shaped that isn't a
 * button should carry this or another class; docs/rebrand/probe_pages.py flags
 * a visible, class-less, underlined anchor as unstyled. */
/* Applied by class where a link is written by hand, and by context everywhere
 * prose links already live — page intros, empty notes, help text — so the
 * dozens of existing inline links get the treatment without every template
 * having to be edited to name it. */
.text-link,
.page-intro a,
.form-switch a,
.empty-note a,
.es-message a,
.form-field small a,
.card-note a,
.simple-list .muted a {
  color: var(--color-primary);
  font-weight: 550;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  text-decoration-color: color-mix(in srgb, var(--color-primary) 45%, transparent);
}

.text-link:hover,
.page-intro a:hover,
.form-switch a:hover,
.empty-note a:hover,
.es-message a:hover,
.form-field small a:hover,
.card-note a:hover,
.simple-list .muted a:hover {
  text-decoration-color: currentColor;
}

/* "← My devices" above a form or detail page. Reads as navigation rather than
 * as a link inside a sentence, so it loses the underline and sits muted until
 * hovered. */
.back-link {
  display: inline-block;
  margin-bottom: var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  font-weight: 550;
  text-decoration: none;
}

.back-link:hover {
  color: var(--color-primary);
}

/* Links inside a console table: the row's name, and its Edit/Delete/Download
 * actions. Underlining every one turns a dense table into a mess of rules, so
 * they carry weight and colour instead and underline only on hover. */
.console-table a {
  color: var(--color-primary);
  font-weight: 550;
  text-decoration: none;
}

.console-table a:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* The row's own identifying link reads as the row's title, not as one of the
 * actions beside it. */
.console-table .cell-strong a {
  color: var(--color-text);
}

.console-table .cell-strong a:hover {
  color: var(--color-primary);
}

/* The "already have an account?" line under a login/register form. */
.form-switch {
  margin: var(--space-4) 0 0;
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

/* ================= Status indicators ================= */

.status-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.status-dot-sm {
  width: 8px;
  height: 8px;
  flex: none;
}

.status-on {
  background: var(--color-success);
}

.status-off {
  background: var(--color-muted);
}

.status-badge {
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--color-border);
  font-size: 0.75rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 550;
  border-radius: 999px;
  padding: 2px var(--space-3);
  white-space: nowrap;
}

.pill.online {
  background: color-mix(in srgb, var(--color-success) 12%, transparent);
  color: var(--color-success);
}

.pill.offline {
  background: color-mix(in srgb, var(--color-muted) 18%, transparent);
  color: var(--color-text-muted);
}

.pill.attention {
  background: color-mix(in srgb, var(--color-warning) 14%, transparent);
  color: var(--color-warning);
}

/* Same wash as .pill.offline, under a name that reads correctly for a badge
 * that isn't about being up or down — a role, say. Bare `.pill` has no
 * background at all, so a badge without a variant renders as plain text and
 * stops looking like a badge. */
.pill.neutral {
  background: color-mix(in srgb, var(--color-muted) 18%, transparent);
  color: var(--color-text-muted);
}

.sev {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.6875rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: var(--radius-sm);
  padding: 2px 7px;
  white-space: nowrap;
}

.sev.warning {
  background: color-mix(in srgb, var(--color-warning) 15%, transparent);
  color: var(--color-warning);
}

.sev.critical {
  background: color-mix(in srgb, var(--color-danger) 13%, transparent);
  color: var(--color-danger);
}

.sev.ok {
  background: color-mix(in srgb, var(--color-success) 13%, transparent);
  color: var(--color-success);
}

/* ================= Stat tiles & card grids ================= */

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.stat {
  padding: var(--space-4);
}

.stat .label {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: 0.6875rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-text-muted);
}

/* Stat-tile icons reuse the sidebar nav's own SVGs verbatim (same markup, same
 * meaning) so a device/alert/dashboard icon means the same thing wherever it
 * appears on the site — sized down slightly, since 16px next to 11px
 * uppercase label text otherwise dominates the tile's top line. */
.stat .label svg {
  flex: none;
  width: 13px;
  height: 13px;
}

.stat .value {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: var(--letter-spacing-display);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.stat .delta {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.stat .delta .up {
  color: var(--color-success);
  font-weight: 600;
}

.stat .delta .down {
  color: var(--color-danger);
  font-weight: 600;
}

.grid-2 {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
  align-items: start;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-4);
  align-items: start;
}

/* Grid items default to min-width:auto, which refuses to shrink below their
 * content's min-content width — that stops a wide child (a .console-table with
 * its own overflow-x:auto) from ever scrolling, and pushes the page sideways
 * instead. */
.grid-2 > *,
.grid-3 > * {
  min-width: 0;
}

.card-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* ================= Lists (devices, alerts, dashboards) ================= */

.device-list {
  display: flex;
  flex-direction: column;
}

.device-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) 0;
  border-top: 1px solid var(--color-border);
}

.device-row:first-child {
  border-top: none;
}

.device-row .name {
  font-weight: 550;
  font-size: var(--font-size-sm);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.device-row .name a {
  color: inherit;
  text-decoration: none;
}

.device-row .meta {
  color: var(--color-text-muted);
  font-size: 0.75rem;
  margin-top: 1px;
}

.device-metric {
  text-align: right;
}

.device-metric .reading {
  font-weight: 600;
  font-size: var(--font-size-base);
  font-variant-numeric: tabular-nums;
}

.device-metric .metric-name {
  color: var(--color-text-muted);
  font-size: 0.6875rem;
}

/* Overview's "My devices" card: today's ingest trend, sitting below the
 * device rows. Reuses .chart-svg/renderLineChart (static/js/charts.js) as-is
 * — same chart the admin Fleet overview page already draws, just scoped to
 * one user's own devices and to today instead of a trailing 24h window. */
.card-inset-chart {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}

.chart-caption {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
}

.simple-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.simple-list li {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-top: 1px solid var(--color-border);
  font-size: var(--font-size-sm);
}

.simple-list li:first-child {
  border-top: none;
}

.simple-list .grow {
  flex: 1;
  min-width: 0;
}

.simple-list .title {
  font-weight: 550;
}

.simple-list .title a {
  color: inherit;
  text-decoration: none;
}

.simple-list .muted {
  color: var(--color-text-muted);
  font-size: 0.75rem;
}

.simple-list .when {
  color: var(--color-text-muted);
  font-size: 0.75rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.empty-note {
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  margin: 0;
}

/* ================= Empty states ================= */

/* templates/partials/empty_state.html — an illustration, a line of copy and,
 * where there's somewhere useful to go, a real call to action. Replaces the
 * bare `.empty-note` paragraph on the pages a new account lands on first,
 * where "nothing here" was doing none of the work of saying what to do next. */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-2);
  padding: var(--space-8) var(--space-4);
}

/* For an empty state inside an already-small card (the Overview's side
 * column) rather than as a whole page body. */
.empty-state-compact {
  padding: var(--space-6) var(--space-2);
}

.es-art {
  width: 96px;
  margin-bottom: var(--space-2);
  color: var(--color-accent-strong);
}

.empty-state-compact .es-art {
  width: 72px;
}

.es-art svg {
  display: block;
  width: 100%;
  height: auto;
}

/* The illustrations carry no presentation attributes — every stroke resolves
 * here, so they follow the theme. See docs/rebrand/css_sanity.py check 5,
 * which fails the build if one of these class names stops matching. */
.es-box {
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: var(--accent-wash);
}

.es-chip,
.es-tile {
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  opacity: 0.75;
}

.es-pin,
.es-rule {
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  opacity: 0.55;
}

.es-line {
  stroke: var(--series-1);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.es-spark {
  stroke: var(--color-muted);
  stroke-width: 2;
  stroke-linecap: round;
}

.es-dot {
  fill: var(--color-success);
}

.es-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 650;
  color: var(--color-text);
}

.es-message {
  margin: 0 0 var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  max-width: 46ch;
  line-height: 1.6;
}

/* An inline caution inside a form, for a choice whose consequences are hard to
 * undo — currently only the Flash firmware page's over-the-air option, where a
 * wrong WiFi password means a USB reflash to recover.
 *
 * Warning colour is a backdrop here, never the message: the text says what is
 * risky on its own, per the tokens.css rule that warning UI stays icon- or
 * text-labeled and is never distinguished by colour alone. Uses
 * --color-warning through color-mix, matching .sev.warning/.pill.attention. */
.form-warning {
  margin: var(--space-2) 0 0;
  padding: var(--space-2) var(--space-3);
  border-left: 3px solid var(--color-warning);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--color-warning) 12%, transparent);
  color: var(--color-text);
  font-size: var(--font-size-sm);
  line-height: 1.6;
}

/* Needed explicitly: the `display` above... does not exist, but any future one
 * would have the same specificity as the browser's `[hidden] { display: none }`
 * and would silently beat it, which is exactly how the "Detect via USB" button
 * and its fallback message both once rendered at the same time. Declared up
 * front so this element cannot join that list. */
.form-warning[hidden] {
  display: none;
}

/* ================= Onboarding checklist ================= */

/* templates/partials/onboarding_checklist.html. Sits directly under the page
 * heading on the Overview and disappears for good once all four steps are
 * genuinely done — see apps/dashboards/views.py:_onboarding_steps. */
.onboard {
  margin-bottom: var(--space-4);
  border-color: color-mix(in srgb, var(--color-accent) 35%, var(--color-border));
  background:
    linear-gradient(
      160deg,
      var(--accent-wash),
      transparent 42%
    ),
    var(--color-surface);
}

.onboard[hidden] {
  display: none;
}

.onboard-head {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.onboard-art {
  width: 48px;
  flex: none;
  color: var(--color-accent-strong);
}

.onboard-art svg {
  display: block;
  width: 100%;
  height: auto;
}

.onboard-heading {
  min-width: 0;
  flex: 1;
}

.onboard-heading h3 {
  margin: 0;
  font-size: var(--font-size-lg);
  font-weight: 700;
}

.onboard-heading p {
  margin: 2px 0 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

.onboard-dismiss {
  flex: none;
  align-self: flex-start;
}

.ob-ring {
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  opacity: 0.28;
}

.ob-wire {
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  opacity: 0.55;
}

.ob-board {
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linejoin: round;
  fill: var(--accent-wash);
}

.ob-check {
  stroke: var(--color-success);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.onboard-track {
  height: 6px;
  border-radius: 999px;
  background: var(--color-border);
  overflow: hidden;
  margin-bottom: var(--space-6);
}

.onboard-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--color-accent-strong);
  transition: width 0.3s ease;
}

.onboard-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.onboard-step {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border);
}

.onboard-step:first-child {
  padding-top: 0;
  border-top: none;
}

/* The step number, replaced by a tick once done. */
.onboard-mark {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 0.8125rem;
  font-weight: 700;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
}

.onboard-mark svg {
  width: 14px;
  height: 14px;
}

.onboard-step.is-done .onboard-mark {
  background: color-mix(in srgb, var(--color-success) 14%, transparent);
  border-color: color-mix(in srgb, var(--color-success) 40%, transparent);
  color: var(--color-success);
}

.onboard-step-body {
  flex: 1;
  min-width: 0;
}

.onboard-step-title {
  margin: 0;
  font-size: var(--font-size-sm);
  font-weight: 600;
}

/* Done steps recede rather than disappear — the list still reads as a
 * sequence, and seeing what's already finished is the point of a checklist. */
.onboard-step.is-done .onboard-step-title {
  color: var(--color-text-muted);
  text-decoration: line-through;
  text-decoration-color: var(--color-muted);
  font-weight: 500;
}

.onboard-step-note {
  margin: 2px 0 0;
  color: var(--color-text-muted);
  font-size: 0.8125rem;
}

.onboard-step-cta {
  flex: none;
  font-size: var(--font-size-sm);
  padding: var(--space-2) var(--space-3);
}

/* Screen-reader-only text ("(done)" on a completed step, where the state is
 * otherwise carried by a tick icon and a strikethrough). */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (max-width: 640px) {
  .onboard-step {
    flex-wrap: wrap;
  }

  /* Onto its own row rather than squeezed beside the text, indented to line
     up with the step body instead of the number bubble. The basis subtracts
     that indent: `flex-basis: 100%` plus a left margin is 100% + margin, which
     overflowed the page by exactly the indent (caught as a 1px document
     overflow at 390px, since the margin also pushed the row's own width). */
  .onboard-step-cta {
    flex: 0 0 calc(100% - 26px - var(--space-3));
    margin-left: calc(26px + var(--space-3));
    text-align: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  .onboard-fill {
    transition: none;
  }
}

/* ================= Tables ================= */

.console-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

.console-table th,
.console-table td {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
}

.console-table th {
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.console-table .cell-strong {
  font-weight: 550;
}

.console-table .cell-muted {
  color: var(--color-text-muted);
  font-size: 0.75rem;
}

.console-table .cell-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.console-table .cell-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.7rem;
  color: var(--color-text-muted);
  word-break: break-all;
}

@media (max-width: 640px) {
  .console-table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}

/* Search + filter controls sitting in a .card-head, opposite the heading —
 * the pattern the System console's users table uses. Wraps onto its own line
 * rather than squeezing the heading, since .card-head is a flex row. */
.console-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  /* Pushed to the far end of the .card-head flex row, same as .card-head
     .link — without it the controls sit jammed against the heading. */
  margin-left: auto;
}

.console-filters select,
.console-filters input[type="search"] {
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
}

.console-filters input[type="search"] {
  min-width: 0;
  width: 14rem;
  max-width: 100%;
}

/* Row under a paginated console table: count on the left, page links right. */
.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.pager-links {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
  margin-bottom: var(--space-4);
}

.toolbar .form-field {
  margin-bottom: 0;
}

/* ================= Charts (fleet overview / overview) ================= */

.chart-svg {
  display: block;
  width: 100%;
  height: auto;
}

.chart-svg text {
  font-family: var(--font-family);
  font-size: 11px;
  fill: var(--color-text-muted);
}

.chart-svg .endpoint-label {
  fill: var(--color-text);
  font-weight: 650;
}

.gridline {
  stroke: var(--chart-grid);
  stroke-width: 1;
}

.axisline {
  stroke: var(--chart-axis);
  stroke-width: 1;
}

.series-line {
  fill: none;
  stroke: var(--chart-line);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.series-area {
  fill: var(--chart-line);
  opacity: 0.1;
}

.series-end {
  fill: var(--chart-line);
  stroke: var(--color-surface);
  stroke-width: 2;
}

.crosshair {
  stroke: var(--color-muted);
  stroke-width: 1;
  visibility: hidden;
}

.hover-dot {
  fill: var(--chart-line);
  stroke: var(--color-surface);
  stroke-width: 2;
  visibility: hidden;
}

.hbar-rows {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.hbar-row {
  display: grid;
  grid-template-columns: 130px 1fr 40px;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--font-size-sm);
}

.hbar-row .cat {
  color: var(--color-text-muted);
}

.hbar-track {
  height: 12px;
  position: relative;
}

.hbar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--chart-line);
  border-radius: 0 4px 4px 0;
}

.hbar-row .val {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.vbars {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 120px;
  padding-top: 14px;
  border-bottom: 1px solid var(--chart-axis);
}

.vbar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  height: 100%;
  justify-content: flex-end;
}

.vbar {
  width: 100%;
  max-width: 24px;
  background: var(--chart-bad);
  border-radius: 4px 4px 0 0;
}

.vbar-col .day {
  font-size: 0.6875rem;
  color: var(--color-text-muted);
}

.vbar-col .peak {
  font-size: 0.6875rem;
  font-weight: 650;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}

.rank-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

.rank-table td {
  padding: var(--space-2) 0;
  border-top: 1px solid var(--color-border);
  vertical-align: middle;
}

.rank-table tr:first-child td {
  border-top: none;
}

.rank-table .dev {
  font-weight: 550;
}

.rank-table .owner {
  color: var(--color-text-muted);
  font-size: 0.75rem;
}

.rank-table .n {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
  padding-left: var(--space-3);
}

.rank-table .barcell {
  width: 34%;
  padding-left: var(--space-3);
}

.rank-bar {
  height: 8px;
  background: var(--chart-line);
  border-radius: 0 3px 3px 0;
  min-width: 3px;
}

.spark .line {
  fill: none;
  stroke: var(--chart-line);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.spark .end {
  fill: var(--chart-line);
}

#chart-tooltip {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  background: var(--color-text);
  color: var(--color-bg);
  font-size: 0.75rem;
  font-weight: 550;
  padding: 5px 9px;
  border-radius: 6px;
  visibility: hidden;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ================= Responsive ================= */

@media (max-width: 880px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 0 0 40px rgba(15, 23, 42, 0.25);
  }

  .shell.drawer-open .sidebar {
    transform: translateX(0);
  }

  .shell.drawer-open #backdrop {
    display: block;
  }

  #hamburger {
    display: grid;
  }

  /* The sidebar is a drawer now, so the topbar title is the only thing saying
   * which page this is — undo the visually-hidden clipping applied above. */
  .topbar-title {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip-path: none;
    min-width: 0;
    text-overflow: ellipsis;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .device-row {
    grid-template-columns: 1fr auto;
  }

  .device-row .spark-cell {
    display: none;
  }
}

@media (max-width: 640px) {
  .content {
    padding: var(--space-3);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar {
    transition: none;
  }

  /* The spin is the only signal that a refresh is in flight, so it can't just
   * be removed — the button's own `disabled` dimming carries that instead. */
  .refresh-btn-spinning .refresh-icon {
    animation: none;
  }
}
