/*
 * Design tokens.
 *
 * Light values live on bare :root. Dark values are declared twice - once under
 * the OS media query (guarded so an explicit light stamp still wins) and once
 * under the theme toggle - so the toggle beats the OS setting in both
 * directions. No color is ever defined only inside a media block.
 *
 * Series hues are the validated three-slot categorical set (blue / orange /
 * aqua). Slot order is the colorblind-safety mechanism, not decoration - do not
 * reorder or add a fourth without re-running the palette validator.
 */

:root {
  color-scheme: light;

  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  /*
   * `--page` is the flat colour (nav hover, wells); `--page-bg` is what body
   * paints. They differ only in dark, where the 2018 app's backdrop was a
   * gradient rather than a flat fill.
   */
  --page-bg: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --field-bg: #ffffff;
  --field-border: rgba(11, 11, 11, 0.18);
  /*
   * The headline row's backing. The legacy gave those two cards their own
   * #1c1d2b, a step darker than the standard card, so the filled block inside
   * them reads as sitting on something. Light mode has no equivalent, so it
   * uses the ordinary card surface.
   */
  --shell: #fcfcfb;

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;

  /*
   * Filled buttons, which carry white text and so need more contrast than a
   * chart series does. Separate from --series-1 for exactly that reason.
   */
  --primary: #2a78d6;

  /* Sequential blue ramp - used for the quota meter track/fill. */
  --seq-100: #cde2fb;
  --seq-250: #86b6ef;
  --seq-450: #2a78d6;

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;

  /*
   * The 2018 dashboard's card colours, carried over so the screen still reads as
   * the same product - with the one thing that was broken about them fixed.
   *
   * There, phase 1 was orange in the Units row but dark red in the Current and
   * Load rows, and phase 3 was green in one and gold in the other. The bar charts
   * agreed with only the first mapping. Here each phase owns exactly one hue,
   * in the tiles and in every chart, and the mapping is the charts' one.
   *
   * `--tile-total` marks a figure covering all three phases, so an aggregate is
   * never mistaken for a fourth category.
   *
   * The originals were picked for a dark navy card (#27293d, or #1c1d2b where
   * the row shell overrode it). Several are too light against this app's light
   * surface, so the light values below are darkened; the dark theme restores the
   * legacy hexes exactly.
   */
  --tile-p1: #e85d1a;
  --tile-p2: #b81010;
  --tile-p3: #14a110;
  --tile-total: #b8860b;
  --tile-month: #3119f3;
  --tile-meter: #e02234;

  --card-shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.05);
  --radius: 12px;
  --font: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

/*
 * Dark theme: the 2018 application's own palette.
 *
 * The legacy app was built on Creative Tim's Black Dashboard, and every value
 * below is lifted from public/css/black-dashboard.css rather than invented:
 *
 *   body / .main-panel   linear-gradient(#1e1e2f, #1e1e24)
 *   .card                #27293d
 *   .card label          rgba(255, 255, 255, 0.6)
 *   .card-footer .stats  #9a9a9a
 *   .card-chart .table   border rgba(255, 255, 255, 0.1)
 *   primary / info       #1d8cf8
 *   success              #00f2c3
 *   warning              #ff8d72
 *   danger               #fd5d93   (#ec250d for the strongest state)
 *
 * That navy-on-navy backdrop is the thing people recognise the product by, so
 * dark mode now matches it. Light mode is unchanged - the legacy app had no
 * light mode to copy (its `.white-content` variant was never enabled).
 *
 * The one thing NOT carried over is Poppins. It is a Google Fonts request on
 * every page load, which costs a round trip to a third party and leaks visitor
 * IPs; the system stack renders immediately. Say the word if you want it back.
 *
 * Declared twice - once under the OS media query, once under the toggle - so
 * neither can override the other by accident. Keep the two lists identical.
 */

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;

    --surface-1: #27293d;
    --page: #1e1e2f;
    --page-bg: linear-gradient(#1e1e2f, #1e1e24);
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.6);
    --text-muted: #9a9a9a;
    --gridline: rgba(255, 255, 255, 0.1);
    --baseline: rgba(255, 255, 255, 0.22);
    --border: rgba(255, 255, 255, 0.1);
    --field-bg: #1e1e2f;
    --field-border: #2b3553;
    --shell: #1c1d2b;
    --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.22);

    --series-1: #1d8cf8;
    --series-2: #ff8d72;
    --series-3: #00f2c3;

    /*
     * The dark end of the legacy btn-primary gradient (#3358f4 -> #1d8cf8).
     * White on #1d8cf8 alone is 3.4:1, which is below the 4.5:1 that 13px label
     * text needs; the gradient's own darker stop clears it at 5.5:1 and is just
     * as much the original palette.
     */
    --primary: #3358f4;

    --seq-100: #1f3a63;
    --seq-250: #1565b5;
    --seq-450: #1d8cf8;

    --status-good: #00f2c3;
    --status-warning: #ff8d72;
    --status-serious: #fd5d93;
    --status-critical: #ec250d;

    /* The legacy tile hexes, unmodified - they were drawn for #27293d. */
    --tile-p1: #ff7433;
    --tile-p2: #b81010;
    --tile-p3: #14a110;
    --tile-total: #daa520;
    --tile-month: #3119f3;
    --tile-meter: #ff3346;
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;

  --surface-1: #27293d;
  --page: #1e1e2f;
  --page-bg: linear-gradient(#1e1e2f, #1e1e24);
  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.6);
  --text-muted: #9a9a9a;
  --gridline: rgba(255, 255, 255, 0.1);
  --baseline: rgba(255, 255, 255, 0.22);
  --border: rgba(255, 255, 255, 0.1);
  --field-bg: #1e1e2f;
  --field-border: #2b3553;
  --shell: #1c1d2b;
  --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.22);

  --series-1: #1d8cf8;
  --series-2: #ff8d72;
  --series-3: #00f2c3;

  --primary: #3358f4;

  --seq-100: #1f3a63;
  --seq-250: #1565b5;
  --seq-450: #1d8cf8;

  --status-good: #00f2c3;
  --status-warning: #ff8d72;
  --status-serious: #fd5d93;
  --status-critical: #ec250d;

  --tile-p1: #ff7433;
  --tile-p2: #b81010;
  --tile-p3: #14a110;
  --tile-total: #daa520;
  --tile-month: #3119f3;
  --tile-meter: #ff3346;
}

* {
  box-sizing: border-box;
}

/*
 * The `hidden` attribute must actually hide.
 *
 * Browsers implement it as `[hidden] { display: none }` in the user-agent
 * stylesheet, which any author-level `display` beats. `.toggle` sets
 * `display: inline-flex`, so a hidden toggle stayed visible - it looked
 * clickable while the JavaScript that wires it had not run yet. Every element
 * this app hides is toggled by script, so raising the specificity here is the
 * correct fix rather than patching each rule.
 */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  /*
   * The gradient is painted on the fixed viewport, not on the document box.
   * Without this a long dashboard stretches the ramp over several screens, so
   * the top of the page and the bottom are visibly different colours - the
   * legacy app scrolled its content inside a fixed panel and never showed that.
   */
  background: var(--page-bg);
  background-attachment: fixed;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------------- layout -- */

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

.brand {
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.nav {
  display: flex;
  gap: 4px;
  flex: 1;
  flex-wrap: wrap;
}

.nav a {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
}

.nav a:hover {
  background: var(--page);
  color: var(--text-primary);
}

.nav a.active {
  background: var(--page);
  color: var(--text-primary);
}

.main {
  padding: 20px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
}

.section {
  margin-bottom: 28px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0;
}

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

/*
 * Cards carry a soft shadow as well as a border.
 *
 * On the navy backdrop a 1px border alone leaves cards looking painted on. The
 * shadow is what separates the surface from the page - kept low-opacity and
 * high-blur so it reads as depth rather than as an outline.
 */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--card-shadow);
}

/* --------------------------------------------------------- tile accents -- */

/*
 * Three treatments, all driven by one --accent custom property set per tile.
 *
 * These reproduce the 2018 dashboard's card rows exactly: filled cards with
 * white text for units and load, a 1px outline for the instantaneous voltage
 * and current readout, and a label-over-filled-block pair for the two headline
 * figures. The hue means the same thing in each - it identifies the phase - so
 * only the weight changes, and it changes with how the row is meant to be read.
 */

/* Rows 2 and 4 of the legacy screen: the whole card in the hue. */
.tile-solid {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/*
 * Row 3: a 1px edge in the hue, card otherwise untouched.
 *
 * Kept at 1px rather than thickened, because the legacy row used the border to
 * label the card, not to weight it against the filled rows around it.
 */
.tile-outline {
  border: 1px solid var(--accent);
}

/*
 * Row 1: the label sits on the card, the value in a filled block beneath it.
 *
 * The legacy markup nested a coloured .card inside a #1c1d2b .card-tasks to get
 * this; one element with a background on the value does the same thing without
 * the nesting.
 */
.tile-headline {
  background: var(--shell);
}

/*
 * text-align, not justify-content: .tile-value and .hero are block boxes whose
 * children are inline spans, so centring is a text-alignment problem. Making
 * them flex to use justify-content would also break the unit's baseline
 * alignment against the number.
 */
.tile-headline .hero,
.tile-headline .tile-value {
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: 12px 16px;
  margin-top: 10px;
  text-align: center;
}

.tile-headline .hero-unit,
.tile-headline .tile-unit {
  color: rgba(255, 255, 255, 0.85);
}

/*
 * The two headline blocks sit side by side, so their numbers want similar
 * weight. The hero still leads - it is the one figure the screen is about - but
 * 26px next to 52px inside two identical coloured blocks reads as a mistake.
 */
.tile-headline .tile-value {
  font-size: 34px;
}

/*
 * The quieter option, used by Reports.
 *
 * Eight filled cards above a chart is a lot of colour competing with the chart's
 * own series. A 3px edge carries the same identity at a fraction of the weight.
 *
 * padding-left compensates for the extra 2px of border so the label stays on the
 * same optical line as tiles that have no accent.
 */
.tile-accent {
  border-left: 3px solid var(--accent, var(--border));
  padding-left: 14px;
}

/*
 * White on a saturated fill, as the legacy had it.
 *
 * Note this is the one place the app knowingly runs below its contrast floor:
 * white on #daa520 is 2.2:1 and on #ff7433 2.7:1, where 4.5:1 is the threshold
 * for the 12px label. It is deliberate - these are the client's colours and the
 * original put white on them - but if the gold and orange tiles turn out to be
 * hard to read, switching those two to dark text is a two-line change here.
 */
.tile-solid .tile-label {
  color: #fff;
}

.tile-solid .tile-value,
.tile-solid .hero {
  color: #fff;
  text-align: center;
}

.tile-solid .tile-unit,
.tile-solid .hero-unit,
.tile-solid .tile-sub {
  color: rgba(255, 255, 255, 0.85);
}

/* The legacy centred every tile value, filled or outlined. */
.tile-solid .tile-sub,
.tile-outline .tile-value,
.tile-outline .tile-sub {
  text-align: center;
}

.grid {
  display: grid;
  gap: 12px;
}

.grid-kpi {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.grid-2 {
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
}

/*
 * The legacy dashboard laid its tiles out in fixed 25% and 50% columns, which
 * broke below about 900px. auto-fit keeps the same reading order and the same
 * groupings while letting a row reflow to two-up or one-up on a narrow screen.
 */
.grid-3 {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.grid-4 {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

/* A wide chart beside a narrow one - the legacy's col-lg-9 / col-lg-3 split. */
.grid-main-side {
  grid-template-columns: minmax(0, 3fr) minmax(0, 1fr);
}

@media (max-width: 1100px) {
  .grid-main-side {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ------------------------------------------------------- dashboard head -- */

.dash-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.dash-date {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------- stat tile -- */

.tile-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.tile-value {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  /* Proportional figures: tabular-nums makes standalone numbers look loose. */
}

.tile-unit {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-left: 4px;
}

.tile-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* The one number the dashboard leads with. */
.hero {
  font-size: 52px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.hero-unit {
  font-size: 18px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-left: 6px;
}

/* ----------------------------------------------------------------- meter -- */

.meter-track {
  height: 8px;
  border-radius: 4px;
  background: var(--seq-100);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
}

/* ---------------------------------------------------------------- legend -- */

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: center;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  /* Text wears text tokens; the swatch beside it carries identity. */
  color: var(--text-secondary);
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: none;
}

/* ----------------------------------------------------------------- chart -- */

.chart-wrap {
  position: relative;
  width: 100%;
}

.chart-svg {
  display: block;
  width: 100%;
  overflow: visible;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14);
  z-index: 5;
  min-width: 150px;
}

.tooltip-title {
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.tooltip-row {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: space-between;
  color: var(--text-secondary);
}

.tooltip-row b {
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

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

.table-scroll {
  overflow-x: auto;
  max-height: 460px;
  overflow-y: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  text-align: right;
  padding: 7px 10px;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

th:first-child,
td:first-child {
  text-align: left;
  font-variant-numeric: normal;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--surface-1);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  z-index: 1;
}

tfoot td {
  font-weight: 600;
  border-top: 2px solid var(--baseline);
  border-bottom: none;
}

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

.filters {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 12px;
  color: var(--text-muted);
}

/* ------------------------------------------------- report parameter picker -- */

/*
 * Full width so it drops to its own line below the filters rather than
 * squeezing between them - it is a set of twenty-odd options, not one control.
 */
.params {
  flex-basis: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.params-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.params-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 6px 14px;
}

.param {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  cursor: pointer;
}

/* The global input rule sizes text fields; a checkbox needs none of it. */
.param input {
  width: 15px;
  height: 15px;
  padding: 0;
  margin: 0;
  accent-color: var(--primary);
}

/*
 * The fixed company half of a machine code, welded to the input beside it so the
 * pair reads as one field showing one value.
 */
.code-prefix {
  font-size: 13px;
  padding: 7px 2px 7px 10px;
  border: 1px solid var(--field-border);
  border-right: 0;
  border-radius: 8px 0 0 8px;
  background: var(--page);
  color: var(--text-muted);
  white-space: nowrap;
}

.link-button {
  border: 0;
  background: none;
  padding: 0;
  font-size: 12px;
  color: var(--primary);
  text-decoration: underline;
  cursor: pointer;
}

textarea {
  font-family: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--field-border);
  background: var(--field-bg);
  color: var(--text-primary);
  resize: vertical;
}

/* A column of fields, as opposed to .filters which is a row of them. */
.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
}

/*
 * Destructive actions are outlined rather than filled.
 *
 * A row of solid red buttons reads as an error state, and the weight pulls the
 * eye towards the one thing on the page nobody should click by accident.
 */
button.danger {
  border-color: var(--status-critical);
  color: var(--status-critical);
}

button.danger:hover:not(:disabled) {
  background: var(--status-critical);
  border-color: var(--status-critical);
  color: #fff;
}

/* --------------------------------------------------------------- subnav -- */

.subnav {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.subnav-item {
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  /* Transparent, not absent, so the active tab does not shift its neighbours. */
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.subnav-item:hover {
  color: var(--text-primary);
}

.subnav-item.active {
  color: var(--text-primary);
  border-bottom-color: var(--primary);
}

/* The address a company signs in at - meant to be copied, so it stands out. */
.portal-hint {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px dashed var(--field-border);
  border-radius: var(--radius);
  background: var(--page);
}

.portal-url {
  font-size: 13px;
  /* Long URLs must wrap rather than push the card wide. */
  word-break: break-all;
  color: var(--text-primary);
}

/* ------------------------------------------------------------------ knox -- */

.page-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 2px;
}

/*
 * minmax(260px, 1fr) rather than a fixed column count: a fleet is however many
 * machines it is, and the same grid has to read on a phone and on the wall
 * display someone leaves this page open on.
 */
.knox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.knox-card {
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.knox-card:hover {
  border-color: var(--baseline);
  transform: translateY(-1px);
}

/*
 * An inactive machine is dimmed, not hidden. It is still part of the fleet and
 * still worth seeing; it just should not compete with the ones that are running.
 */
.knox-card.is-inactive {
  opacity: 0.62;
}

.knox-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.knox-name {
  font-weight: 600;
  font-size: 15px;
  line-height: 1.3;
}

.knox-code,
.knox-company {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.knox-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}

/*
 * Three equal columns so the same figure sits in the same place on every card -
 * that alignment is what makes a column of cards scannable rather than a set of
 * things to read one by one.
 */
.knox-figures {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.knox-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 3px;
}

.knox-value {
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.knox-unit {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 2px;
}

.knox-spark {
  display: block;
  width: 100%;
  height: 24px;
  overflow: visible;
}

.knox-spark-empty {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
}

.knox-foot {
  font-size: 12px;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: auto;
}

/* ------------------------------------------------------------------ auth -- */

.signout {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
}

.signout .muted {
  font-size: 12px;
  /* The name is context, not a control; it must not compete with Sign out. */
  max-width: 18ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/*
 * The sign-in card.
 *
 * Centred vertically as well as horizontally, because there is nothing else on
 * the page - anchoring it to the top would leave the eye hunting in a large
 * empty area. min-height rather than height so a validation banner can push the
 * card taller without clipping.
 */
.auth-shell {
  min-height: calc(100vh - 56px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  margin: 0;
}

.auth-card {
  width: 100%;
  /* ch, not px: the measure should follow the font, not the pixel grid. */
  max-width: 42ch;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 28px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.18);
}

/* Three phase bars - the product's own identity, not a generic logo. */
.auth-mark {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
}

.auth-mark span {
  display: block;
  width: 22px;
  height: 4px;
  border-radius: 2px;
}

.auth-title {
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 2px;
}

.auth-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 24px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-form input {
  padding: 10px 12px;
}

.auth-submit {
  margin-top: 4px;
  padding: 10px 14px;
  font-size: 14px;
}

.auth-foot {
  margin: 22px 0 0;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------------------------------------------------------------- print -- */

/*
 * The legacy report tables shipped DataTables' excel/pdf/print buttons, which
 * pulled in jQuery, DataTables, three button plugins, pdfmake and a 1.5 MB font
 * bundle from four CDNs. Print with a stylesheet costs nothing, produces a PDF
 * through the browser's own "Save as PDF", and cannot break when a CDN moves.
 */
@media print {
  .topbar,
  .filters,
  .no-print,
  [data-chart-toggle],
  [data-tab-buttons] {
    display: none !important;
  }

  .main {
    padding: 0;
    max-width: none;
  }

  body {
    background: #fff;
    color: #000;
  }

  .card {
    border-color: #999;
    break-inside: avoid;
  }

  /*
   * Browsers drop background colours when printing unless the user opts in, so a
   * filled tile would print white text on white paper. Undo the fill and put the
   * text back to black; the accent survives as a left edge, which does print.
   */
  .tile-solid,
  .tile-headline .hero,
  .tile-headline .tile-value {
    background: none;
    border-left: 3px solid var(--accent);
    padding-left: 12px;
  }

  .tile-solid,
  .tile-solid .tile-label,
  .tile-solid .tile-value,
  .tile-solid .tile-unit,
  .tile-solid .tile-sub,
  .tile-headline .hero,
  .tile-headline .hero-unit,
  .tile-headline .tile-value,
  .tile-headline .tile-unit {
    color: #000;
    text-align: left;
  }

  /*
   * Scroll containers must not clip in print - the whole point is to get every
   * row onto paper, and an overflow box prints only what was on screen.
   */
  .table-scroll {
    overflow: visible;
    max-height: none;
  }

  thead {
    display: table-header-group;
  }

  tr {
    break-inside: avoid;
  }
}

/*
 * Fields carry their own surface and border tokens because they appear both on
 * the page (the report filters) and inside cards (the meter forms). Reusing
 * --surface-1 made an input invisible in the second case - it was the same
 * colour as the card behind it. The dark values are the legacy theme's, where
 * .form-control was transparent with a #2b3553 outline.
 */
input,
select,
button {
  font-family: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--field-border);
  background: var(--field-bg);
  color: var(--text-primary);
}

button {
  cursor: pointer;
  font-weight: 500;
}

button:hover:not(:disabled) {
  border-color: var(--baseline);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/*
 * CSV export is an <a>, not a <button>: it is a navigation to a different
 * representation of the same report, and it must keep working without
 * JavaScript. This makes it look like the buttons beside it.
 */
.button-link {
  display: inline-block;
  font-size: 13px;
  font-weight: 500;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  text-decoration: none;
  line-height: 1.5;
}

.button-link:hover {
  border-color: var(--baseline);
}

.toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.toggle button {
  border: none;
  border-radius: 0;
  background: var(--surface-1);
  color: var(--text-secondary);
  padding: 5px 12px;
  font-size: 12px;
}

.toggle button[aria-pressed='true'] {
  background: var(--page);
  color: var(--text-primary);
  font-weight: 600;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: none;
}

.banner {
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-1);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

/* Refetch holds the previous render rather than flashing a skeleton. */
.is-loading {
  opacity: 0.55;
  transition: opacity 0.15s ease;
}

.empty {
  padding: 36px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

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

.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

/* --------------------------------------------------------- date navigation -- */

.dash-head-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.date-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

.date-pick {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}

/*
 * Square steppers either side of the calendar. Sized to match the date input's
 * own height so the three read as one control rather than as three.
 */
.date-step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--field-border);
  border-radius: 8px;
  background: var(--field-bg);
  color: var(--text-primary);
  text-decoration: none;
  font-size: 17px;
  line-height: 1;
  /* The chevrons are punctuation, not text: keep them off the baseline grid. */
  padding-bottom: 2px;
}

.date-step:hover {
  border-color: var(--baseline);
  color: var(--text-primary);
}

/*
 * Today is the far edge, and forward stays visible but inert there. A control
 * that disappears at the boundary reads as a bug; one that dims explains itself.
 */
.date-step.is-disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

/* The picker is a date, and dates are numbers - align them like the tiles. */
.date-pick input[type="date"] {
  font-variant-numeric: tabular-nums;
}

/* Navigation is for the screen; a printed report shows one day and says which. */
@media print {
  .date-nav {
    display: none;
  }
}
/* ------------------------------------------------- machine picker + title -- */

.machine-picker {
  display: flex;
  align-items: center;
  gap: 8px;
}

.machine-picker label {
  font-size: 12px;
  white-space: nowrap;
}

/*
 * Capped so a long machine name cannot push the control off a narrow screen,
 * but wide enough that CODE - Name is readable without opening the list.
 */
.machine-picker select {
  max-width: 34ch;
}

/*
 * The code beside the machine name. Lighter and smaller: the name is what a
 * person recognises, the code is what matches the logger - both need to be on
 * the page, but only one of them is the heading.
 */
.title-code {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  margin-left: 6px;
}

@media print {
  /* The heading is the whole point of printing a report - keep it. */
  .machine-picker {
    display: none !important;
  }

  .page-title,
  .title-code {
    color: #000;
  }
}

/* ------------------------------------------------------------ responsive -- */

/*
 * Most of this stylesheet is already fluid by construction: the grids are
 * auto-fit rather than fixed column counts, the toolbars wrap, and the charts
 * are viewBox SVGs that scale to their container. What follows is the set of
 * places where "the same layout, narrower" is not good enough and a phone needs
 * the pieces arranged differently.
 *
 * Scoped to `screen` so a narrow paper size cannot trigger the phone layout in
 * the middle of printing a report.
 */

/* Grid and flex children default to min-width:auto, so one wide cell - a long
 * machine name, a table - can push its whole row past the viewport instead of
 * scrolling inside its own box. */
.grid > *,
.knox-grid > *,
.grid-main-side > * {
  min-width: 0;
}

/* A pasted URL or an unbroken machine code should wrap, not widen the page. */
body {
  overflow-wrap: break-word;
}

@media screen and (max-width: 1024px) {
  .main {
    padding: 16px;
  }
}

@media screen and (max-width: 720px) {

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

  /*
   * Two rows: who and where on the first, the nav on the second.
   *
   * The topbar wrapped its five links into a ragged block three lines deep, so
   * on a phone the page pushed its actual content below the fold before it had
   * said anything. The nav becomes a single scrollable strip instead - every
   * destination stays reachable, and it costs one line however many there are.
   */
  .topbar {
    height: auto;
    min-height: 0;
    align-items: center;
    gap: 8px 10px;
    padding: 8px 12px;
  }

  .brand {
    order: 1;
    flex: 1 1 auto;
    font-size: 15px;
  }

  .topbar > [data-theme-toggle] {
    order: 2;
  }

  .signout {
    order: 3;
  }

  /* The signed-in name is a courtesy; the button is the function. */
  .signout .muted {
    display: none;
  }

  .nav {
    order: 4;
    flex: 0 0 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    /* Bleed to the screen edges so the strip reads as scrollable. */
    margin: 0 -12px;
    padding: 0 12px 2px;
    /* A scrollbar here would eat a third of the strip's height. */
    scrollbar-width: none;
  }

  .nav::-webkit-scrollbar {
    display: none;
  }

  .nav a {
    white-space: nowrap;
    scroll-snap-align: start;
    display: flex;
    align-items: center;
    /* 44px is the smallest touch target that is reliably hittable. */
    min-height: 44px;
  }

  .subnav {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .subnav::-webkit-scrollbar {
    display: none;
  }

  .subnav-item {
    white-space: nowrap;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .main {
    padding: 14px 12px 28px;
  }

  .section {
    margin-bottom: 22px;
  }

  /* ---------------------------------------------------------- headings -- */

  .page-title {
    font-size: 19px;
  }

  .dash-date {
    font-size: 17px;
  }

  .dash-head {
    gap: 10px;
  }

  /* Stacked, so a filter box beside a title does not squeeze both. */
  .section-head {
    align-items: stretch;
    gap: 10px;
  }

  .section-head > input[type="search"] {
    width: 100%;
  }

  /* ------------------------------------------------------------- forms -- */

  /*
   * A grid rather than a wrapping row. Wrapped flex items break wherever the
   * label lengths happen to add up, so From and To could end up on different
   * lines; a two-column grid keeps the pairs together.
   */
  .filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    align-items: end;
  }

  .filters .field {
    min-width: 0;
  }

  .filters input,
  .filters select {
    width: 100%;
  }

  /* flex-basis does nothing in a grid; this is the same intent. */
  .params {
    grid-column: 1 / -1;
  }

  /*
   * 16px on form controls, always.
   *
   * iOS Safari zooms the whole page in when a field smaller than 16px takes
   * focus, and does not zoom back out afterwards - so one tap on a date box
   * leaves the entire dashboard scrolled sideways.
   */
  input,
  select,
  textarea,
  button {
    font-size: 16px;
  }

  input,
  select,
  button,
  .button-link {
    min-height: 44px;
  }

  .button-link {
    display: inline-flex;
    align-items: center;
  }

  /* Checkboxes and inline text buttons are not touch targets in that sense. */
  .param input,
  .link-button {
    min-height: 0;
  }

  .link-button {
    font-size: 13px;
  }

  .params-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px 12px;
  }

  /* The tick box itself should be comfortable even if the row is compact. */
  .param {
    min-height: 32px;
  }

  /* ---------------------------------------------------- machine picker -- */

  /*
   * Full width on its own line. Squeezed beside the heading, the select
   * collapsed to a few characters - which is the one control on the page that
   * has to be readable before you open it.
   */
  .machine-picker {
    width: 100%;
  }

  .machine-picker select {
    flex: 1 1 auto;
    max-width: none;
  }

  /* ------------------------------------------------------------ tables -- */

  /*
   * Reports are genuinely wide - twenty parameters across - so the table keeps
   * scrolling sideways inside its own box rather than being restacked into
   * cards. Rows of a measurement table are compared against each other, and
   * stacking destroys exactly that.
   */
  .table-scroll {
    max-height: 70vh;
  }

  th,
  td {
    padding: 9px 10px;
  }

  /* -------------------------------------------------------------- knox -- */

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

  /* --------------------------------------------------------- sign-in --- */

  .auth-shell {
    /* dvh accounts for the mobile URL bar; vh is the fallback for older
     * browsers, where the card simply sits a little lower. */
    min-height: calc(100vh - 56px);
    min-height: calc(100dvh - 56px);
    padding: 20px 14px;
  }

  .auth-card {
    padding: 26px 20px;
  }
}

@media screen and (max-width: 420px) {
  /*
   * Four KPI tiles across a 360px screen leaves ~80px each, which truncates the
   * numbers they exist to show. Two-up is the narrowest that still reads.
   */
  .grid-4,
  .grid-kpi {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .main {
    padding: 12px 10px 24px;
  }

  .filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tile-headline .hero {
    font-size: 30px;
  }
}
