/* =====================================================================
   MPA — client web app stylesheet
   "MPA style": sans-serif text with Noto Serif for data and headings
   (tables, readings, controls, tabs, titles), soft blue-grey hairline grids,
   the original slider, mode buttons; navy #00334d for selected states.
   Playfair Display is the brand mark only.
   Light and dark theme via tokens; the header colour is one token pair.
   ===================================================================== */

@font-face {
  font-family: "Noto Serif";
  src: url("fonts/noto-serif-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  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: "Noto Serif";
  src: url("fonts/noto-serif-latin-ext.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-017F, U+0218-021B, U+1E9E, U+20AC;
}

@font-face {
  font-family: "Playfair Display";
  src: url("fonts/playfair-display-latin-700.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  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: "Playfair Display";
  src: url("fonts/playfair-display-latin-ext-700.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  color-scheme: light;

  --c-primary: #006699;
  --c-primary-hover: #00557f;
  --c-on-primary: #ffffff;
  --c-primary-container: #d0e8f5;
  --c-on-primary-container: #00334d;
  --c-secondary-container: #b8d8ec;

  --c-navy: #00334d;
  --c-selected-bg: #00334d;
  --c-on-selected: #ffffff;

  /* Table grid lines, slider, switches. */
  --c-rule: #b4c2cc;
  --c-track: #eeeeee;
  --c-tick: #c0c0c0;
  --c-control-disabled: #808080;
  --c-switch-off: #c62828;
  --c-switch-on: #006699;
  --c-valve-on: #2e7d32;
  --switch-icon-off: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M2 2l6 6M8 2l-6 6' stroke='%23fff' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
  --switch-icon-on: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 6.2l2.4 2.4 4.6-5' fill='none' stroke='%23fff' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");

  --c-bg: #ffffff;
  --c-surface: #ffffff;
  --c-surface-tint: #f5f8fa;
  --c-surface-alt: #eeeeee;
  --c-surface-hover: #f5f8fa;
  --c-border: #dddddd;
  --c-border-strong: #b8c0c7;
  --c-outline: #71787f;
  --c-text: #1a1c1e;
  --c-text-muted: #41484f;
  --c-text-faint: #5b636b;

  --c-danger: #b50706;
  --c-danger-hover: #930505;
  --c-on-danger: #ffffff;
  --c-danger-container: #ffdad6;
  --c-on-danger-container: #410002;
  --c-success: #1b7a35;
  --c-success-container: #d9f2df;
  --c-warning: #8a4b00;
  --c-warning-container: #ffe3c4;

  --c-status-connected: #1e9e4a;
  --c-status-connecting: #d65c00;
  --c-status-disconnected: #d50000;

  /* Switch the header to blue by setting these to var(--c-primary) / var(--c-on-primary). */
  --c-header-bg: var(--c-surface);
  --c-header-fg: var(--c-text);
  --c-header-border: var(--c-border);

  --c-focus: #006699;
  --c-backdrop: rgba(10, 20, 30, 0.45);

  --shadow-1: none;
  --shadow-2: 0 4px 12px rgba(16, 24, 40, 0.10), 0 2px 4px rgba(16, 24, 40, 0.06);
  --shadow-3: 0 16px 40px rgba(16, 24, 40, 0.18);

  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 10px;
  --radius-pill: 999px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --font-brand: "Playfair Display", Georgia, "Times New Roman", serif;
  /* Data and headings: tables, readings, controls, tabs, titles. */
  --font-data: "Noto Serif", Georgia, "Times New Roman", serif;

  --header-height: 64px;
  --page-width: 1120px;
  --gutter: 24px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --c-primary: #80caff;
    --c-primary-hover: #a6d8ff;
    --c-on-primary: #003549;
    --c-primary-container: #004d6e;
    --c-on-primary-container: #d0e8f5;
    --c-secondary-container: #2f4d5f;

    --c-navy: #a6d8ff;
    --c-selected-bg: #a6d8ff;
    --c-on-selected: #00253a;

    --c-rule: #3e4a53;
    --c-track: #30373d;
    --c-tick: #5b636b;
    --c-control-disabled: #6b747c;
    --c-switch-off: #ff8a80;
    --c-switch-on: #80caff;
    --c-valve-on: #6fdc8c;
    --switch-icon-off: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M2 2l6 6M8 2l-6 6' stroke='%23111' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
    --switch-icon-on: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 6.2l2.4 2.4 4.6-5' fill='none' stroke='%23111' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");

    --c-bg: #111416;
    --c-surface: #16191c;
    --c-surface-tint: #1b2126;
    --c-surface-alt: #22282d;
    --c-surface-hover: #1f262c;
    --c-border: #30373d;
    --c-border-strong: #4a535b;
    --c-outline: #8a9299;
    --c-text: #e2e8ed;
    --c-text-muted: #bac4cc;
    --c-text-faint: #9aa4ac;

    --c-danger: #ffb4ab;
    --c-danger-hover: #ffcbc4;
    --c-on-danger: #690001;
    --c-danger-container: #5c1410;
    --c-on-danger-container: #ffdad6;
    --c-success: #7fd893;
    --c-success-container: #1d3b25;
    --c-warning: #ffb870;
    --c-warning-container: #46300f;

    --c-status-connected: #4ade80;
    --c-status-connecting: #ffa44d;
    --c-status-disconnected: #ff6b6b;

    --c-focus: #80caff;
    --c-backdrop: rgba(0, 0, 0, 0.6);

    --shadow-1: none;
    --shadow-2: 0 4px 14px rgba(0, 0, 0, 0.45);
    --shadow-3: 0 16px 40px rgba(0, 0, 0, 0.6);
  }
}

/* ~~~~~~~ BASE ~~~~~~~ */

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: calc(var(--header-height) + 16px);
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body.modal-open { overflow: hidden; }

[hidden] { display: none !important; }

h1, h2, h3, h4, p, ul, ol, dl, dd, figure { margin: 0; }

h1, h2 { font-family: var(--font-data); font-weight: 700; letter-spacing: 0; }
h1 { font-size: 32px; line-height: 1.2; }
h2 { font-size: 22px; line-height: 1.25; }
h3 { font-size: 16px; line-height: 1.4; font-weight: 600; }

/* Small caps-style label used for column heads, field labels and tabs. */
.eyebrow {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--c-text-muted);
}

a { color: var(--c-primary); text-underline-offset: 2px; }
a:hover { color: var(--c-primary-hover); }

img, svg { display: block; max-width: 100%; }

button, input, select, textarea { font: inherit; color: inherit; }

::selection { background: var(--c-primary-container); color: var(--c-on-primary-container); }

:focus-visible {
  outline: 2px solid var(--c-focus);
  outline-offset: 2px;
}

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

.skip-link {
  position: absolute;
  left: 16px;
  top: -100px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--c-primary);
  color: var(--c-on-primary);
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus { top: 12px; color: var(--c-on-primary); }

.icon { width: 20px; height: 20px; fill: currentColor; flex: none; }

.muted { color: var(--c-text-muted); }
.faint { color: var(--c-text-faint); }
.small { font-size: 13px; }
.mono { font-family: var(--font-mono); font-size: 0.92em; }
.num { font-variant-numeric: tabular-nums; }
.text-danger { color: var(--c-danger); }
.text-success { color: var(--c-success); }
.nowrap { white-space: nowrap; }
.pre-line { white-space: pre-line; }

/* ~~~~~~~ LAYOUT ~~~~~~~ */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--c-header-bg);
  color: var(--c-header-fg);
  border-bottom: 1px solid var(--c-header-border);
}

.app-header-inner {
  max-width: var(--page-width);
  height: var(--header-height);
  margin: 0 auto;
  padding: 0 var(--gutter);
  display: flex;
  align-items: center;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 12px;
  color: inherit;
  text-decoration: none;
  white-space: nowrap;
  min-width: 0;
}
.brand:hover { color: inherit; }

.brand-mark {
  font-family: var(--font-brand);
  font-weight: 700;
  font-size: 28px;
  line-height: 1;
  letter-spacing: 0.02em;
  color: var(--c-primary);
}

.brand-tagline {
  font-size: 13px;
  color: var(--c-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
}

.main-nav { display: flex; align-items: center; gap: 4px; margin-left: auto; }

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: inherit;
  font-size: 15px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.nav-link:hover { background: var(--c-surface-hover); color: inherit; }
.nav-link.active { background: var(--c-primary-container); color: var(--c-on-primary-container); }

.header-tools { display: flex; align-items: center; gap: 8px; }
/* The header keeps its plain look: no uppercase buttons there. */
.header-tools .btn { text-transform: none; letter-spacing: 0; font-size: 14px; font-weight: 600; }
.header-tools .btn-primary { border-radius: var(--radius); }

.lang-switch {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
}
.lang-switch button {
  min-width: 36px;
  height: 28px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--c-text-muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
}
.lang-switch button:hover { color: var(--c-text); }
.lang-switch button.active { background: var(--c-primary); color: var(--c-on-primary); }

.btn.menu-toggle { display: none; }

.offline-banner {
  padding: 8px var(--gutter);
  background: var(--c-danger-container);
  color: var(--c-on-danger-container);
  text-align: center;
  font-weight: 500;
}

.page {
  flex: 1 0 auto;
  width: 100%;
  max-width: var(--page-width);
  margin: 0 auto;
  padding: 28px var(--gutter) 48px;
}
.page:focus { outline: none; }

.page-narrow { max-width: 440px; margin: 0 auto; }
.page-medium { max-width: 720px; margin: 0 auto; }

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 24px;
  margin-bottom: 20px;
}
.page-header p { color: var(--c-text-muted); margin-top: 4px; }

.app-footer {
  flex: none;
  border-top: 1px solid var(--c-border);
  color: var(--c-text-muted);
  font-size: 13px;
}
.app-footer-inner {
  max-width: var(--page-width);
  margin: 0 auto;
  padding: 18px var(--gutter);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 24px;
}
.app-footer nav { display: flex; flex-wrap: wrap; gap: 4px 20px; }
.app-footer a { color: inherit; }
.app-footer a:hover { color: var(--c-primary); }

.stack { display: flex; flex-direction: column; gap: 20px; }
.stack-sm { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.row-between { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.row-end { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 12px; }
.spacer { flex: 1; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px 20px; }

/* ~~~~~~~ DRAWER (mobile navigation) ~~~~~~~ */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--c-backdrop);
  animation: fade-in 0.15s ease;
}

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 41;
  width: min(320px, 86vw);
  display: flex;
  flex-direction: column;
  background: var(--c-surface);
  box-shadow: var(--shadow-3);
  animation: slide-in-left 0.2s ease;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 12px 0 20px;
  border-bottom: 1px solid var(--c-border);
}

.drawer-nav { display: flex; flex-direction: column; gap: 2px; padding: 12px; }
.drawer-nav .nav-link { height: 48px; padding: 0 16px; border-radius: var(--radius); justify-content: flex-start; }
.drawer-section { padding: 12px 20px; border-top: 1px solid var(--c-border); }
.drawer-section-label { font-size: 12px; font-weight: 600; color: var(--c-text-muted); margin-bottom: 8px; }

/* ~~~~~~~ BUTTONS ~~~~~~~ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--c-primary);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.btn .icon { width: 18px; height: 18px; }

.btn-primary { background: var(--c-primary); color: var(--c-on-primary); }
.btn-primary:hover { background: var(--c-navy); color: var(--c-on-selected); }

.btn-outline { border-color: var(--c-border-strong); color: var(--c-navy); }
.btn-outline:hover { border-color: var(--c-text); background: var(--c-surface-tint); }

.btn-tonal { border-color: var(--c-border); background: var(--c-surface-alt); color: var(--c-text); }
.btn-tonal:hover { border-color: var(--c-text); }

.btn-text { padding: 0 12px; }
.btn-text:hover { background: var(--c-surface-hover); }

.btn-danger { background: var(--c-danger); color: var(--c-on-danger); }
.btn-danger:hover { background: var(--c-danger-hover); color: var(--c-on-danger); }

.btn-danger-text { padding: 0 12px; color: var(--c-danger); }
.btn-danger-text:hover { background: var(--c-danger-container); color: var(--c-on-danger-container); }

.btn-sm { height: 32px; padding: 0 12px; font-size: 11.5px; }
.btn-lg { height: 48px; padding: 0 28px; font-size: 13px; }
.btn-block { width: 100%; }

.btn-icon {
  width: 40px;
  padding: 0;
  border-radius: 50%;
  color: var(--c-text-muted);
}
.btn-icon:hover { background: var(--c-surface-hover); color: var(--c-text); }
.btn-icon.btn-sm { width: 32px; }
.btn-icon .icon { width: 22px; height: 22px; }

.btn:disabled,
.btn[aria-disabled="true"] {
  background: var(--c-surface-alt);
  border-color: transparent;
  color: var(--c-text-faint);
  box-shadow: none;
  filter: none;
  cursor: not-allowed;
}
.btn-text:disabled, .btn-icon:disabled, .btn-danger-text:disabled,
.btn-text[aria-disabled="true"], .btn-icon[aria-disabled="true"] { background: transparent; }

/* ~~~~~~~ CARDS ~~~~~~~ */

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--c-border);
  background: var(--c-surface-tint);
  border-radius: var(--radius) var(--radius) 0 0;
}
.card-header h2, .card-header h3 { font-family: var(--font-data); font-size: 20px; font-weight: 700; }
.card-header p { color: var(--c-text-muted); font-size: 13px; margin-top: 2px; }

.card-body { padding: 20px; }
.card-body.flush { padding: 0; }

.card-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 20px;
  border-top: 1px solid var(--c-border);
}

/* ~~~~~~~ FORMS ~~~~~~~ */

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

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }

.field-label { font-size: 11.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--c-text-muted); }
.field-label .faint { font-weight: 400; letter-spacing: 0; text-transform: none; }

.field-hint { font-size: 12.5px; color: var(--c-text-muted); }

.field-error {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: 12.5px;
  color: var(--c-danger);
}

.input, .select, .textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius-sm);
  background: var(--c-surface);
  color: var(--c-text);
  font-size: 15px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.select { padding-right: 36px; appearance: none; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--c-text-muted) 50%), linear-gradient(135deg, var(--c-text-muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
.input::placeholder, .textarea::placeholder { color: var(--c-text-faint); }

.input:hover, .select:hover, .textarea:hover { border-color: var(--c-text); }

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 1px var(--c-primary);
}

.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] {
  border-color: var(--c-danger);
  box-shadow: 0 0 0 1px var(--c-danger);
}

.input:disabled, .select:disabled, .textarea:disabled, .input[readonly] {
  background: var(--c-surface-alt);
  color: var(--c-text-muted);
  border-color: var(--c-border);
  cursor: not-allowed;
}

.input.num { text-align: right; }
.input-sm { min-height: 36px; padding: 6px 10px; font-size: 14px; }

.input-with-action { position: relative; }
.input-with-action .input { padding-right: 48px; }
.input-with-action .btn-icon { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); }

.input-with-unit { display: flex; align-items: center; gap: 8px; }
.input-with-unit .input { flex: 1; min-width: 0; }
.input-with-unit .unit { color: var(--c-text-muted); font-size: 14px; }

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
  cursor: pointer;
}
.check-row input[type="checkbox"], .check-row input[type="radio"] {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  flex: none;
  accent-color: var(--c-primary);
  cursor: pointer;
}

.form-message {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.form-message.is-error { background: var(--c-danger-container); color: var(--c-on-danger-container); }
.form-message.is-success { background: var(--c-success-container); color: var(--c-success); }

/* ~~~~~~~ SWITCH (native checkbox, role="switch") ~~~~~~~
   Drawn like the power slider: a thin rounded track (grey when off, filled blue when on) and a round knob,
   red with a cross when off, blue (settings) or green (valves, .switch-valve) with a tick when on.
   The symbol keeps the state readable without colour. */

.switch {
  appearance: none;
  position: relative;
  flex: none;
  width: 42px;
  height: 22px;
  margin: 0;
  border: 0;
  border-radius: 11px;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.switch::after {
  content: "";
  position: absolute;
  left: 4px;
  right: 4px;
  top: 50%;
  height: 6px;
  margin-top: -3px;
  border-radius: 20px;
  background: var(--c-track);
  transition: background-color 0.15s ease;
}
.switch::before {
  content: "";
  position: absolute;
  z-index: 1;
  top: 2px;
  left: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--switch-icon-off) center / 9px 9px no-repeat, var(--c-switch-off);
  box-shadow: 0 0 0 2px var(--c-surface), 0 1px 3px 2px rgba(0, 0, 0, 0.18);
  transition: transform 0.18s ease, background-color 0.15s ease;
}
.switch:checked::after { background: var(--c-primary); }
.switch:checked::before { transform: translateX(24px); background: var(--switch-icon-on) center / 11px 11px no-repeat, var(--c-switch-on); }
.switch-valve:checked::before { background: var(--switch-icon-on) center / 11px 11px no-repeat, var(--c-valve-on); }
.switch:disabled { cursor: not-allowed; opacity: 0.45; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 48px;
  cursor: pointer;
}
.switch-row .switch-label { font-size: 14px; }

/* ~~~~~~~ SLIDER (the original range slider) ~~~~~~~
   <div class="range-slider"><input class="slider" type="range"><div class="range-slider-progress"></div></div>
   The view sets --fill (0-100) on the wrapper; ticks mark every tenth of the scale. */

.range-slider {
  --thumb-size: 16px;
  --track-height: calc(var(--thumb-size) / 3);
  --ticks-height: 5px;
  --fill: 0;
  position: relative;
  z-index: 0;
  display: inline-block;
  flex: none;
  width: 200px;
  max-width: 100%;
  height: calc(var(--thumb-size) + var(--ticks-height));
  background: linear-gradient(to right, var(--c-tick) 1px, transparent 1px) repeat-x;
  background-size: calc((100% - var(--thumb-size)) / 10) var(--ticks-height);
  background-position: calc(var(--thumb-size) / 2 - 0.5px) bottom;
  vertical-align: middle;
}

.range-slider-progress {
  position: absolute;
  z-index: -1;
  left: calc(var(--thumb-size) / 2);
  right: calc(var(--thumb-size) / 2);
  top: calc(var(--thumb-size) / 2 - var(--track-height) / 2);
  height: var(--track-height);
  border-radius: 20px;
  background: var(--c-track);
  pointer-events: none;
}
.range-slider-progress::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--c-primary);
  clip-path: inset(-20px calc(100% - var(--fill) * 1%) -20px 0);
}

.range-slider > .slider {
  appearance: none;
  -webkit-appearance: none;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: var(--thumb-size);
  margin: 0;
  background: none;
  outline: none;
  cursor: grab;
}
.range-slider > .slider:active { cursor: grabbing; }
.range-slider > .slider::-webkit-slider-runnable-track { background: none; }
.range-slider > .slider::-moz-range-track { background: none; }
.range-slider > .slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: var(--thumb-size);
  height: var(--thumb-size);
  border: none;
  border-radius: 50%;
  background: var(--c-primary);
  transition: 0.1s;
}
.range-slider > .slider::-moz-range-thumb {
  width: var(--thumb-size);
  height: var(--thumb-size);
  border: none;
  border-radius: 50%;
  background: var(--c-primary);
}
.range-slider > .slider:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--c-surface), 0 0 0 5px var(--c-focus); }
.range-slider > .slider:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 3px var(--c-surface), 0 0 0 5px var(--c-focus); }
.range-slider > .slider:disabled { cursor: not-allowed; }
.range-slider > .slider:disabled::-webkit-slider-thumb { background: var(--c-control-disabled); }
.range-slider > .slider:disabled::-moz-range-thumb { background: var(--c-control-disabled); }
.range-slider > .slider:disabled ~ .range-slider-progress::before { background: var(--c-control-disabled); }

.slider-field { display: flex; flex-direction: column; gap: 6px; }
.slider-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }

/* ~~~~~~~ MODE BUTTONS (the original process mode buttons) ~~~~~~~ */

.mode-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.mode-btn {
  padding: 4px 10px;
  border: 1px solid var(--c-border);
  border-radius: 5px;
  background: var(--c-surface-alt);
  color: var(--c-text);
  font-family: var(--font-data);
  font-size: 15px;
  line-height: 1.25;
  cursor: pointer;
}
.mode-btn:hover { border-color: var(--c-text); }
.mode-btn.active { border-color: var(--c-selected-bg); background: var(--c-selected-bg); color: var(--c-on-selected); }
.mode-btn:disabled, .mode-btn[aria-disabled="true"] { cursor: not-allowed; opacity: 0.4; }
.mode-btn:disabled:hover, .mode-btn[aria-disabled="true"]:hover { border-color: var(--c-border); }
/* The current mode stays readable while the buttons are locked or offline. */
.mode-btn.active:disabled { opacity: 1; border-color: var(--c-selected-bg); }

/* ~~~~~~~ CHIPS (small toggle values, e.g. favourite valve openings) ~~~~~~~ */

.chip {
  min-width: 44px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius-sm);
  background: var(--c-surface);
  color: var(--c-navy);
  font-family: var(--font-data);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.chip:hover { border-color: var(--c-navy); background: var(--c-surface-tint); }
.chip.active { border-color: var(--c-selected-bg); background: var(--c-selected-bg); color: var(--c-on-selected); }
.chip:disabled { cursor: not-allowed; opacity: 0.45; }
.chip:disabled:hover { border-color: var(--c-border-strong); background: var(--c-surface); }

/* ~~~~~~~ TABS (route navigation) ~~~~~~~ */

.tabs {
  display: flex;
  gap: 4px;
  margin: 0 0 20px;
  padding: 0;
  list-style: none;
  border-bottom: 1px solid var(--c-border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  height: 48px;
  padding: 0 18px;
  border: 0;
  background: transparent;
  color: var(--c-text-muted);
  font-family: var(--font-data);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.tab:hover { color: var(--c-text); }
.tab.active { color: var(--c-navy); }
.tab.active::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: -1px;
  height: 3px;
  background: var(--c-navy);
}

/* ~~~~~~~ TABLES (the original records table: black hairline grid, no outer frame) ~~~~~~~ */

.table-wrap { width: 100%; overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  border-style: hidden;
  font-family: var(--font-data);
  font-size: 15px;
}
.table th, .table td {
  padding: 10px;
  border: 1px solid var(--c-rule);
  text-align: center;
  vertical-align: middle;
}
.table th { font-weight: 700; color: var(--c-navy); background: var(--c-surface-tint); }
.table tbody tr.is-clickable { cursor: pointer; }
.table tbody tr.is-clickable:hover td { background: var(--c-surface-tint); }
.table .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .actions { white-space: nowrap; width: 1%; }
.table .actions .btn + .btn { margin-left: 4px; }
.table .empty { padding: 32px 16px; color: var(--c-text-muted); }
.table-compact td, .table-compact th { padding: 6px 8px; }

@media (max-width: 1100px) {
  .table { font-size: clamp(12px, 3.2vw, 15px); }
  .table th, .table td { padding: clamp(4px, 1vw, 10px); }
}

/* ~~~~~~~ TEMPERATURES (the original process table) ~~~~~~~ */

.temps {
  margin: 0 auto;
  border-collapse: collapse;
  border-style: hidden;
  font-family: var(--font-data);
  font-variant-numeric: tabular-nums;
  line-height: normal;
}
.temps th, .temps td {
  padding: 4px 10px;
  border: 1px solid var(--c-rule);
  color: var(--c-text);
  font-size: min(5.4vw, 30px);
  font-weight: 400;
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}
.temps thead th { padding: 6px 10px; font-size: min(4.2vw, 21px); font-style: italic; color: var(--c-text-muted); }
.temps .temps-title { padding: 6px 14px; font-size: min(5.6vw, 30px); font-weight: 700; font-style: normal; color: var(--c-navy); }
.temps .temps-unit { font-weight: 400; color: var(--c-text-muted); }
.temps th[scope="row"] { font-size: min(4.6vw, 24px); color: var(--c-navy); }
.temps .temps-stab { text-align: left; padding-left: 10px; }
.temps .temps-diff { margin-left: 6px; font-size: min(3vw, 14px); vertical-align: top; color: var(--c-text-faint); }
.temps .temps-empty { padding: 16px; font-size: 16px; white-space: normal; color: var(--c-text-muted); }
.temps .is-inactive, .temps .is-inactive th, .temps .is-inactive td { color: var(--c-text-faint); }

/* ~~~~~~~ KEY / VALUE ~~~~~~~ */

.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 20px;
  font-size: 14px;
}
.kv dt { color: var(--c-text-muted); }
.kv dd { font-variant-numeric: tabular-nums; min-width: 0; overflow-wrap: anywhere; }

/* ~~~~~~~ COLLAPSIBLE SECTIONS ~~~~~~~ */

.sections { border-bottom: 1px solid var(--c-rule); }
.section { border-top: 1px solid var(--c-rule); }
.section h2 { font-size: inherit; }

.section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  padding: 10px 6px;
  border: 0;
  background: transparent;
  color: var(--c-navy);
  font-family: var(--font-data);
  font-size: 17px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.section-header:hover { background: var(--c-surface-tint); }
.section-header > span:first-child { flex: 1; min-width: 0; }
.section-header .section-meta { font-family: var(--font); font-size: 13px; font-weight: 500; color: var(--c-text-muted); }
/* Chevron: down when closed, up when open. */
.section-header::after {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  margin: 0 6px 4px;
  border: solid var(--c-text-muted);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  transition: transform 0.2s;
}
.section-header[aria-expanded="true"]::after { margin-bottom: -4px; transform: rotate(-135deg); }

.section-body { padding: 8px 6px 28px; }
.section-note { margin-bottom: 14px; text-align: center; font-size: 14px; color: var(--c-text-muted); }
.section-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }

/* ~~~~~~~ STATUS / BADGES / ALERTS ~~~~~~~ */

.status-dot {
  display: inline-block;
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--c-text-faint);
}
.status-dot.is-connected { background: var(--c-status-connected); }
.status-dot.is-connecting { background: var(--c-status-connecting); }
.status-dot.is-disconnected { background: var(--c-status-disconnected); }

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--c-text-muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 8px;
  border-radius: 3px;
  background: var(--c-surface-alt);
  color: var(--c-text-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge-primary { background: var(--c-primary-container); color: var(--c-on-primary-container); }
.badge-success { background: var(--c-success-container); color: var(--c-success); }
.badge-danger { background: var(--c-danger-container); color: var(--c-on-danger-container); }
.badge-warning { background: var(--c-warning-container); color: var(--c-warning); }

.alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--c-surface-alt);
  font-size: 14px;
}
.alert .icon { margin-top: 1px; }
.alert-danger { background: var(--c-danger-container); color: var(--c-on-danger-container); }
.alert-info { background: var(--c-primary-container); color: var(--c-on-primary-container); }
.alert-warning { background: var(--c-warning-container); color: var(--c-warning); }
.alert-title { font-weight: 600; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 48px 16px;
  text-align: center;
  color: var(--c-text-muted);
}
.empty-state .icon { width: 56px; height: 56px; opacity: 0.45; }
.empty-state h2 { color: var(--c-text); font-size: 17px; }

/* ~~~~~~~ MODALS ~~~~~~~ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: var(--c-backdrop);
  animation: fade-in 0.15s ease;
}

.modal {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 48px);
  background: var(--c-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
  animation: pop-in 0.18s ease;
}
.modal:focus { outline: none; }
.modal-wide { max-width: 760px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 16px 14px 24px;
}
.modal-title { font-size: 18px; font-weight: 600; }

.modal-body { padding: 4px 24px 20px; overflow-y: auto; }

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 24px 20px;
}
.modal-footer .spacer { flex: 1; }

/* ~~~~~~~ LOADERS ~~~~~~~ */

.spinner {
  display: inline-block;
  width: 28px;
  height: 28px;
  border: 3px solid var(--c-secondary-container);
  border-top-color: var(--c-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.spinner-sm { width: 18px; height: 18px; border-width: 2px; }
.btn .spinner { width: 16px; height: 16px; border-width: 2px; border-color: currentColor; border-top-color: transparent; }

.loading-block {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px 16px;
  color: var(--c-text-muted);
}

/* ~~~~~~~ FAVOURITES STRIP ~~~~~~~ */

/* Stays under the header while the page scrolls, so another device is always one tap away. */
.devices-bar {
  position: sticky;
  top: calc(var(--header-height) + 1px);
  z-index: 15;
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin: -10px 0 12px;
  padding: 10px 0;
  background: var(--c-bg);
}

.fav-list {
  display: flex;
  flex: 1;
  min-width: 0;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-x: auto;
  scrollbar-width: none;
}
.fav-list::-webkit-scrollbar { display: none; }
.fav-list > li { flex: none; min-width: 0; }

.fav-tile {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 44px;
  max-width: 240px;
  padding: 0 14px 0 10px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-surface);
  color: var(--c-text);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}
.fav-tile:hover { border-color: var(--c-outline); color: var(--c-text); }
.fav-tile.active {
  border-color: var(--c-selected-bg);
  background: var(--c-selected-bg);
  color: var(--c-on-selected);
}
.fav-tile.active .fav-icon { color: var(--c-on-selected); }

.fav-icon { position: relative; flex: none; display: flex; color: var(--c-primary); }
.fav-icon .icon { width: 24px; height: 24px; }
.fav-icon .status-dot {
  position: absolute;
  right: -3px;
  top: -3px;
  width: 9px;
  height: 9px;
  box-shadow: 0 0 0 2px var(--c-surface);
}
.fav-tile.active .fav-icon .status-dot { box-shadow: 0 0 0 2px var(--c-selected-bg); }

.fav-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.fav-more {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-surface);
  color: var(--c-text-muted);
  cursor: pointer;
}
.fav-more:hover, .fav-more[aria-expanded="true"] { border-color: var(--c-outline); color: var(--c-text); }
.fav-more .fav-more-label { display: none; }
.fav-more .icon { width: 30px; height: 30px; }

/* Desktop: tiles get a minimum width; "more" is the big dots with a label and no frame, next to the tiles. */
@media (min-width: 601px) {
  .fav-tile { min-width: 150px; }
  .fav-more { width: auto; padding: 0 12px 0 6px; gap: 4px; border-color: transparent; background: transparent; color: var(--c-navy); font-size: 14px; font-weight: 600; }
  .fav-more:hover, .fav-more[aria-expanded="true"] { border-color: transparent; background: var(--c-surface-hover); color: var(--c-navy); }
  .fav-more .fav-more-label { display: inline; }
  .fav-more .icon { width: 26px; height: 26px; }
}

.device-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  width: min(320px, 100%);
  max-height: min(420px, 70vh);
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-surface);
  box-shadow: var(--shadow-2);
}
.device-menu-list { margin: 0; padding: 0; list-style: none; }
.device-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 6px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--c-text);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.device-menu-item:hover { background: var(--c-surface-hover); }
.device-menu-item.active { background: var(--c-surface-tint); color: var(--c-navy); font-weight: 600; }
.device-menu-item .icon { color: var(--c-primary); }
.device-menu-item .device-menu-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-menu-divider { height: 1px; margin: 6px 4px; background: var(--c-border); }
.device-menu-add { color: var(--c-navy); font-weight: 600; }

/* ~~~~~~~ DEVICE HEADER ~~~~~~~ */

.device-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-bottom: 4px;
}
/* One line: icon, name, then model and serial number. */
/* One line, one size: model and serial number first (their length is fixed), then the name. */
.device-title { display: flex; align-items: baseline; gap: 8px; min-width: 0; font-size: 14px; }
.device-meta { color: var(--c-text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
.device-meta:not(:empty)::after { content: "·"; margin-left: 8px; }
.device-title h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font); font-size: inherit; font-weight: 600; color: var(--c-navy); }

/* ~~~~~~~ COOKIE NOTICE ~~~~~~~ */

.cookie-notice {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 45;
  display: flex;
  align-items: center;
  gap: 16px 24px;
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 20px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  background: var(--c-surface);
  box-shadow: var(--shadow-3);
  font-size: 14px;
  animation: slide-up 0.25s ease;
}
.cookie-notice p { flex: 1; }
.cookie-notice a { white-space: nowrap; }

/* ~~~~~~~ HOME ~~~~~~~ */

.hero {
  padding: 12px 0 28px;
  border-bottom: 1px solid var(--c-border);
}
.hero h1 { font-size: 44px; line-height: 1.1; color: var(--c-navy); }
.hero h1::after {
  content: "";
  display: block;
  width: 56px;
  height: 3px;
  margin-top: 16px;
  background: var(--c-primary);
}
.hero p { margin-top: 14px; max-width: 70ch; font-size: 17px; color: var(--c-text-muted); }
.hero a { font-weight: 600; }

.product-list { display: flex; flex-direction: column; gap: 16px; }

.product-card .card-body { display: flex; flex-direction: column; gap: 16px; }
.product-card ul { padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }

.gallery {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding-bottom: 4px;
}
.gallery button {
  flex: none;
  padding: 0;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
  scroll-snap-align: start;
}
.gallery button.active { border-color: var(--c-primary); }
.gallery img { width: 96px; height: 72px; object-fit: cover; border-radius: 4px; }
.gallery-main { width: 100%; max-height: 420px; object-fit: contain; border-radius: var(--radius); background: var(--c-surface-alt); }

/* ~~~~~~~ PROSE (legal pages) ~~~~~~~ */

.prose { max-width: 75ch; font-size: 15px; line-height: 1.65; }
.prose h1 { margin-bottom: 8px; }
.prose h2 { margin: 32px 0 10px; font-size: 18px; }
.prose h3 { margin: 20px 0 6px; font-size: 15px; }
.prose p, .prose ul, .prose ol, .prose table { margin: 0 0 12px; }
.prose ul, .prose ol { padding-left: 22px; }
.prose li + li { margin-top: 4px; }
.prose .table { margin: 8px 0 16px; }
.prose .lead { color: var(--c-text-muted); }
.prose .alert p { margin: 0; }

/* =====================================================================
   Screen-specific styles. Each area owns only the space between its markers.
   ===================================================================== */

/* ~~~~~~~ AREA: devices — favourites strip, device menu, manager, device header and tabs ~~~~~~~ */

/* Favourites strip: room for focus outlines inside the horizontally scrolling list. */
.fav-list { padding: 3px; margin: -3px; }
.fav-tile.active:hover { border-color: var(--c-primary); color: var(--c-on-primary-container); }

/* Device menu: items are links. */
a.device-menu-item { text-decoration: none; }
.device-menu-item:hover { color: var(--c-text); }
.device-menu-item.active:hover { background: var(--c-primary-container); color: var(--c-on-primary-container); }
.device-menu-item.device-menu-empty { color: var(--c-text-muted); cursor: default; }
.device-menu-item.device-menu-empty:hover { background: transparent; }

/* Device frame */
.device-header .status { margin: 0; }

/* Manager */
.manager-card .manager-title { font-size: 20px; }
.manager-name { display: inline-flex; align-items: center; gap: 10px; font-weight: 500; }
.manager-name .icon { color: var(--c-primary); }
.manager-favourite.active, .manager-favourite.active:hover { color: var(--c-primary); }
.manager-table td.center { width: 1%; }
.manager-serial-inline { display: none; }

@media (max-width: 600px) {
  .manager-col-model, .manager-col-type, .manager-col-serial { display: none; }
  .manager-serial-inline { display: block; font-size: 12px; font-weight: 400; color: var(--c-text-muted); }
  .manager-table td, .manager-table th { padding-left: 10px; padding-right: 10px; }
  .manager-table .actions .btn span { display: none; }
  .manager-table .actions .btn { width: 32px; padding: 0; }
}

/* ~~~~~~~ END AREA: devices ~~~~~~~ */

/* · */
/* · */
/* · */

/* ~~~~~~~ AREA: process — controller process screen ~~~~~~~ */

/* The temperatures table and every controls grid share one centred column, so they start and end together. */
.process { --process-column: 32rem; display: flex; flex-direction: column; gap: 20px; }
.process .temps { width: var(--process-column); max-width: 100%; }
.process-offline { justify-content: center; }

/* Controls grid: label | value | control, as wide as the temperatures table. Every grid (controls, valves,
   stabilization, recording) uses the same columns, so they all line up under the table. */
.pc-grid {
  --pc-cols: 8.5rem 5.5rem minmax(0, 1fr);
  display: grid;
  grid-template-columns: var(--pc-cols);
  width: var(--process-column);
  max-width: 100%;
  margin: 0 auto;
  align-items: center;
  gap: 14px 16px;
  font-family: var(--font-data);
  font-size: 15px;
}
.process-controls { margin-bottom: 8px; }
.pc-group, .pc-row { display: contents; }
.pc-wide { grid-column: 1 / -1; }
.pc-label { color: var(--c-text-muted); white-space: nowrap; }
/* The pressed mode button says which mode is on, so the buttons start in the value column. */
.process-controls .mode-buttons, .pc-mode-hint { grid-column: 2 / -1; }
.pc-value { color: var(--c-navy); font-variant-numeric: tabular-nums; white-space: nowrap; }
.pc-wide-value { grid-column: 2 / -1; color: var(--c-navy); font-variant-numeric: tabular-nums; }
.pc-state { font-size: 13px; color: var(--c-text-muted); }
.pc-control { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; min-width: 0; }
.pc-hint { font-family: var(--font); font-size: 12.5px; color: var(--c-text-muted); }
label.pc-row { cursor: pointer; }
.mode-buttons { flex-wrap: nowrap; }
.pc-mode-hint { margin-top: -6px; }

/* Thermostat: its own small grid in a 1px frame, the name cut into the top line; its state comes last. */
.thermostat {
  position: relative;
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 8px 20px;
  margin-top: 10px;
  padding: 20px 16px 14px;
  border: 1px solid var(--c-rule);
  border-radius: var(--radius);
}
.thermostat .pc-wide-value { grid-column: 2; }
.thermostat-legend {
  position: absolute;
  top: -0.75em;
  left: 12px;
  margin: 0;
  padding: 0 8px;
  background: var(--c-bg);
  font-family: var(--font-data);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--c-navy);
}
.thermostat-status { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; margin: 0; color: var(--c-text-muted); }
.thermostat-details { display: contents; }
.thermostat-details dd { margin: 0; }

/* Auto process and alcohol readings */
.process-auto, .process-alcohol { margin: 0 auto; border-collapse: collapse; font-family: var(--font-data); }
.process-auto th, .process-auto td,
.process-alcohol th, .process-alcohol td { padding: 3px 8px; text-align: left; font-weight: 400; }
.process-auto th, .process-alcohol th { text-align: right; color: var(--c-text-muted); }
.process-auto { font-size: 18px; }
.process-auto td { color: var(--c-navy); }
.process-alcohol { font-size: 16px; }
.process-alcohol td { font-weight: 700; color: var(--c-navy); font-variant-numeric: tabular-nums; }
.process-countdown { margin: 12px 0 16px; text-align: center; font-family: var(--font-data); font-size: 34px; color: var(--c-navy); font-variant-numeric: tabular-nums; }
.process-auto + .process-countdown[hidden] + .section-actions { margin-top: 16px; }

/* Precision valves: favourite openings as chips, then the "set any value" button. */
.pvalve-open { display: inline-flex; align-items: center; justify-content: center; min-width: 40px; padding: 0 6px; }
.pvalve-open .pvalve-icon { width: 22px; height: 22px; fill: none; }


.pvalve-icon circle { fill: var(--c-surface); }

.process-sending {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  box-shadow: var(--shadow-2);
  font-size: 14px;
  font-weight: 500;
  transform: translateX(-50%);
}

@media (max-width: 600px) {
  .pc-grid { --pc-cols: max-content minmax(3.5rem, auto) minmax(0, 1fr); width: 100%; gap: 14px 10px; }
  .section-header .section-meta { display: none; }
  .mode-buttons { gap: 4px; }
  .mode-btn { padding: 4px 8px; font-size: 14px; }
  .pvalve-controls { gap: 4px; }
  .pc-control { flex-wrap: nowrap; }
  .pvalve-controls { flex-wrap: wrap; }
  .pc-control .btn-sm { padding: 0 10px; }
  .chip { min-width: 38px; padding: 0 6px; }
}

/* ~~~~~~~ END AREA: process ~~~~~~~ */

/* · */
/* · */
/* · */

/* ~~~~~~~ AREA: settings — controller settings screen ~~~~~~~ */

.settings-items { display: flex; flex-direction: column; gap: 12px; }

.settings-item {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 18px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-surface);
}
.settings-item-title { font-size: 15px; }
.settings-item .grid-2, .settings-item .grid-3 { align-items: start; }
.settings-item .switch-row { align-self: center; }

.settings-slider-value {
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.settings-thermostat { max-width: 560px; }
.settings-select-field { max-width: 280px; }

.settings-favourites { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.settings-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }

.settings-savebar {
  position: sticky;
  bottom: 12px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 16px;
  box-shadow: var(--shadow-2);
}
.settings-savebar-status { flex: 1; min-width: 0; font-size: 14px; color: var(--c-danger); }
.settings-savebar-status:empty { visibility: hidden; }

@media (max-width: 600px) {
  .settings-item { padding: 14px; }
  .settings-savebar { bottom: 8px; }
  .settings-savebar .btn { width: 100%; }
  .settings-savebar-status { flex-basis: 100%; text-align: center; }
}

/* ~~~~~~~ END AREA: settings ~~~~~~~ */

/* · */
/* · */
/* · */

/* ~~~~~~~ AREA: thermometers — thermometers process and settings ~~~~~~~ */

/* Settings: one fieldset per thermometer. */
.thermo-settings-list { display: flex; flex-direction: column; gap: 16px; }
.thermo-fieldset {
  margin: 0;
  padding: 12px 16px 4px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  min-width: 0;
}
.thermo-fieldset legend { padding: 0 6px; font-size: 14px; font-weight: 600; }
.thermo-fieldset .switch-row { margin-top: 4px; }

/* Settings: alcohol measurement thermometers. */
.thermo-positions { margin: 0; padding: 0; list-style: none; }
.thermo-position {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 6px 0;
  border-bottom: 1px solid var(--c-border);
}
.thermo-position:last-child { border-bottom: 0; }
.thermo-position-text { display: flex; flex-direction: column; min-width: 0; }
.thermo-position-label { font-size: 13px; color: var(--c-text-muted); }
.thermo-position-value { font-weight: 600; overflow-wrap: anywhere; }

/* Settings: save bar under the sections. */
.thermo-save-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }

@media (max-width: 600px) {
  .thermo-fieldset { padding: 10px 12px 2px; }
  .thermo-save-bar .btn { flex: 1; }
  .thermo-save-bar .form-message { flex-basis: 100%; text-align: center; }
}

/* ~~~~~~~ END AREA: thermometers ~~~~~~~ */

/* · */
/* · */
/* · */

/* ~~~~~~~ AREA: records — records list and record details ~~~~~~~ */

.records-alert { margin: 16px 20px 0; }

.records-title-link { font-weight: 500; color: var(--c-text); text-decoration: none; overflow-wrap: anywhere; }
.records-title-link:hover { color: var(--c-primary); text-decoration: underline; }
.table .records-date { white-space: nowrap; font-variant-numeric: tabular-nums; }

.records-detail-header { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.records-detail-header .row-between { width: 100%; }
.records-back { margin-left: -12px; }
.records-detail-title { min-width: 0; overflow-wrap: anywhere; }
.records-actions { gap: 4px; }

.records-note-label { font-size: 13px; font-weight: 600; color: var(--c-text-muted); }
.records-note { font-size: 14px; line-height: 1.55; overflow-wrap: anywhere; }

.records-edit-form { display: flex; flex-direction: column; min-height: 0; }
.records-fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
.records-fieldset legend { padding: 0; margin-bottom: 10px; }

@media (max-width: 600px) {
  .table .records-date { white-space: normal; }
}

/* ~~~~~~~ END AREA: records ~~~~~~~ */

/* · */
/* · */
/* · */

/* ~~~~~~~ AREA: pages — home, contact, account, legal ~~~~~~~ */

/* Home: the welcome message is admin-provided HTML, so it lives in a div rather than a <p>. */
.hero-message { margin-top: 10px; max-width: 70ch; font-size: 16px; }
.hero-message p + p { margin-top: 8px; }
.product-description { line-height: 1.65; }
.product-doc-link { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }

/* Contact */
.contact-sent:empty { display: none; }
.contact-message { min-height: 200px; }
.contact-direct { text-align: center; color: var(--c-text-muted); }
.contact-direct a { overflow-wrap: anywhere; }
@media (min-width: 601px) {
  .contact-phone { max-width: calc(50% - 10px); }
}

/* ~~~~~~~ END AREA: pages ~~~~~~~ */

/* · */
/* · */
/* · */

/* ~~~~~~~ ANIMATIONS ~~~~~~~ */

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes slide-in-left { from { transform: translateX(-100%); } to { transform: none; } }
@keyframes slide-up { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .spinner { animation-duration: 1.6s !important; animation-iteration-count: infinite !important; }
}

/* ~~~~~~~ RESPONSIVE ~~~~~~~ */

@media (max-width: 960px) {
  .main-nav, .header-tools .lang-switch, .header-tools .nav-link { display: none; }
  .btn.menu-toggle { display: inline-flex; margin-left: -8px; }
  .app-header-inner { gap: 8px; }
  .brand { margin-right: auto; }
}

@media (max-width: 600px) {
  :root { --gutter: 16px; --header-height: 56px; }

  body { font-size: 15px; }
  .brand-mark { font-size: 24px; }
  .brand-tagline { display: none; }
  .page { padding-top: 20px; }

  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .card-header, .card-body { padding-left: 16px; padding-right: 16px; }
  .card-footer { padding-left: 16px; padding-right: 16px; }
  .hero { padding: 4px 0 20px; }
  .hero h1 { font-size: 32px; }

  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal { max-width: none; max-height: 92vh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .modal-header { padding-left: 20px; }
  .modal-body, .modal-footer { padding-left: 20px; padding-right: 20px; }

  h1 { font-size: 26px; }
  .device-title { font-size: 13px; }

  .cookie-notice { flex-direction: column; align-items: stretch; left: 8px; right: 8px; bottom: 8px; }
  .cookie-notice .btn { width: 100%; }

  /* Favourites: five equal columns (up to four favourites and "more"). */
  .devices-bar { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
  .fav-list { display: contents; }
  .fav-list > li { min-width: 0; }
  .fav-tile {
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 100%;
    max-width: none;
    height: 68px;
    padding: 6px 4px;
    font-size: 11px;
  }
  .fav-tile .icon { width: 26px; height: 26px; }
  .fav-name { max-width: 100%; text-align: center; }
  .fav-more { grid-column: 5; width: 100%; height: 68px; flex-direction: column; gap: 4px; }
  .fav-list > li:nth-child(n+5) { display: none; }
  .device-menu { width: 100%; }


  .tab { padding: 0 14px; }
}

@media (forced-colors: active) {
  .switch, .status-dot, .btn { forced-color-adjust: auto; }
  .tab.active::after { background: Highlight; }
}
