:root {
  color-scheme: light;
  --color-bg: #eef3f1;
  --color-surface: #ffffff;
  --color-surface-strong: #f7faf9;
  --color-text: #15211e;
  --color-muted: #61716c;
  --color-border: #cedbd7;
  --color-accent: #0c776d;
  --color-accent-strong: #075f57;
  --color-focus: #1b67d8;
  --color-danger: #b83232;
  --color-warning: #9a6a00;
  --color-ok: #147444;
  --color-info: #2b5f9e;
  --shadow-panel: 0 18px 45px rgba(21, 33, 30, 0.12);
  --shadow-surface: 0 8px 20px rgba(21, 33, 30, 0.06);
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --radius: 8px;
  --topbar-height: 72px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--color-text);
  background: var(--color-bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

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

h1,
h2,
h3 {
  margin: 0 0 var(--space-3);
  font-weight: 700;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

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

p {
  margin: 0;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

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

.fallback-shell,
.auth-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: var(--space-5);
}

.login-card {
  width: min(100%, 420px);
  padding: var(--space-6);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  box-shadow: var(--shadow-panel);
}

.brand-mark,
.section-kicker {
  margin: 0 0 var(--space-2);
  color: var(--color-accent);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand-mark {
  text-transform: none;
}

.login-card h1,
.workspace-card h1 {
  margin: 0;
}

.workspace-card h1 + p,
.workspace-card > p + p,
.login-card__intro {
  margin-top: var(--space-3);
}

.login-note {
  margin-top: var(--space-4);
}

.login-card__intro,
.login-note,
.muted {
  color: var(--color-muted);
}

.field {
  display: grid;
  gap: var(--space-2);
  margin-top: var(--space-4);
  color: var(--color-text);
  font-weight: 700;
}

.field input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--color-text);
}

.form-error {
  margin: var(--space-4) 0 0;
  color: var(--color-danger);
  font-weight: 700;
}

.form-status {
  margin: var(--space-2) 0 0;
  font-size: 0.9rem;
  font-weight: 700;
}

.form-status--pending,
.form-status--conflict {
  color: var(--color-warning);
}

.form-status--success {
  color: var(--color-ok);
}

.form-status--error,
.form-status--failed {
  color: var(--color-danger);
}

.button,
.icon-button,
.nav-link {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  font-weight: 800;
}

.button--primary {
  width: 100%;
  margin-top: var(--space-5);
  background: var(--color-accent);
  color: #fff;
}

.button--inline {
  width: auto;
  margin-top: 0;
}

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

.button--secondary {
  background: var(--color-surface-strong);
  border-color: var(--color-border);
  color: var(--color-text);
}

.icon-button {
  position: relative;
  flex-shrink: 0;
  width: 40px;
  background: var(--color-surface-strong);
  border-color: var(--color-border);
  color: var(--color-text);
  font-weight: 900;
}

.icon-button.has-unread {
  border-color: var(--color-danger);
}

.notification-count {
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 20px;
  min-height: 20px;
  padding: 1px 5px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: var(--color-danger);
  color: #fff;
  font-size: 0.72rem;
  line-height: 1.2;
}

.dashboard-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto minmax(220px, 1fr) auto;
  gap: var(--space-4);
  align-items: center;
  min-height: var(--topbar-height);
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}

.topbar__brand {
  display: grid;
  gap: 0;
}

.brand-kicker {
  color: var(--color-accent);
  font-size: 0.72rem;
  font-weight: 800;
}

.topbar__nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: center;
}

.nav-link {
  padding: 0 var(--space-3);
  background: transparent;
  color: var(--color-muted);
  font-weight: 800;
}

.nav-link:hover,
.nav-link.is-active {
  background: #e1efec;
  color: var(--color-accent-strong);
}

.topbar__actions {
  display: flex;
  align-items: center;
  justify-content: end;
  gap: var(--space-2);
}

.connection-pill {
  display: grid;
  grid-template-columns: auto auto;
  column-gap: var(--space-2);
  align-items: center;
  min-height: 42px;
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface-strong);
  font-size: 0.86rem;
  font-weight: 800;
}

.connection-pill small {
  grid-column: 2;
  color: var(--color-muted);
  font-weight: 600;
}

.connection-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--color-muted);
}

.connection-pill--connected .connection-dot {
  background: var(--color-ok);
}

.connection-pill--reconnecting .connection-dot,
.connection-pill--stale .connection-dot {
  background: var(--color-warning);
}

.connection-pill--disconnected .connection-dot {
  background: var(--color-danger);
}

.user-chip {
  display: grid;
  min-width: 112px;
  padding: 5px 10px;
  border-left: 1px solid var(--color-border);
}

.user-chip span {
  font-weight: 800;
}

.user-chip small {
  color: var(--color-muted);
}

.dashboard-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-5);
  padding: var(--space-5);
}

.workspace {
  display: grid;
  gap: var(--space-4);
  align-content: start;
}

.dashboard-layout > *,
.workspace > *,
.topbar > *,
.filter-field,
.admin-table-wrap {
  min-width: 0;
}

.workspace-card,
.state-box,
.empty-state,
.notice {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  box-shadow: var(--shadow-surface);
}

.workspace-card {
  padding: var(--space-5);
}

.workspace-card__header {
  margin-bottom: var(--space-4);
}

.state-box,
.empty-state,
.notice {
  padding: var(--space-4);
}

.state-box {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.spinner {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border: 3px solid #c5d5d0;
  border-top-color: var(--color-accent);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

.notice {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
}

.notice--error {
  border-color: #e4b3b3;
  background: #fff8f8;
}

.status-icon {
  display: grid;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 999px;
  font-weight: 900;
}

.status-icon--error {
  background: #f3d7d7;
  color: var(--color-danger);
}

.side-panel {
  align-self: start;
  min-width: 0;
  max-height: calc(100vh - 9rem);
  overflow: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  box-shadow: var(--shadow-panel);
}

/* The analysis detail reconciles its own scroll position. Native scroll
   anchoring would adjust it again while the panel's sections are refreshed. */
.side-panel[data-analysis-panel-key] {
  overflow-anchor: none;
}

.side-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

/* The notification list scrolls inside the panel and grows while it is read.
   Keep its title and close action at the top instead of letting the list push
   them out of view. */
.side-panel[data-notification-panel] .side-panel__header {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--color-surface);
}

.side-panel__header h2 {
  min-width: 0;
  margin: 0;
}

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

.supervision-view {
  position: relative;
  display: grid;
  gap: var(--space-4);
  align-content: start;
}

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

.kpi-card {
  display: grid;
  gap: var(--space-1);
  min-height: 104px;
  padding: var(--space-4);
  text-align: left;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-surface);
}

button.kpi-card {
  cursor: pointer;
}

.kpi-card strong {
  font-size: 1.8rem;
  line-height: 1;
}

.kpi-card small,
.kpi-card__label,
.result-count {
  color: var(--color-muted);
}

.kpi-card--ok {
  border-left: 5px solid var(--color-ok);
}

.kpi-card--danger {
  border-left: 5px solid var(--color-danger);
}

.kpi-card--warning {
  border-left: 5px solid var(--color-warning);
}

.supervision-kpis {
  /* Seven indicators share one row on desktop, with or without the side
     panel; each card keeps the same width and the descriptions stay short. */
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: var(--space-2);
  container-type: inline-size;
}

.supervision-kpis .kpi-card {
  position: relative;
  min-width: 0;
  min-height: 110px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 1.1rem 1.6rem 1.1rem;
  align-content: start;
  gap: 4px;
  padding: 12px 6px;
  border-left-width: 5px;
}

.supervision-kpis .kpi-card strong {
  font-size: clamp(1.25rem, 0.9rem + 0.9cqw, 1.6rem);
}

.supervision-kpis .kpi-card__label,
.supervision-kpis .kpi-card small {
  white-space: nowrap;
  line-height: 1.1rem;
}

/* The label and the description scale with the row width so all seven fit
   without wrapping, truncation or overflow. */
.supervision-kpis .kpi-card__label {
  font-size: clamp(0.68rem, 0.5rem + 0.37cqw, 0.85rem);
}

.supervision-kpis .kpi-card small {
  font-size: clamp(0.7rem, 0.5rem + 0.36cqw, 0.8rem);
}

/* Narrow viewports may reorganize the indicators instead of shrinking them
   below a legible width. */
@media (max-width: 1279px) {
  .supervision-kpis {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr));
    gap: var(--space-3);
  }

  .supervision-kpis .kpi-card {
    min-height: 122px;
    grid-template-rows: 1.25rem 1.8rem 1.25rem;
    gap: 8px;
    padding: 16px;
  }

  .supervision-kpis .kpi-card strong {
    font-size: 1.8rem;
  }

  .supervision-kpis .kpi-card__label {
    font-size: 0.85rem;
  }

  .supervision-kpis .kpi-card small {
    font-size: 0.8rem;
  }
}

.supervision-kpi-tooltip {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 40;
  width: 100%;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--color-text);
  color: var(--color-surface);
  font-size: 0.85rem;
  line-height: 1.4;
  white-space: normal;
  visibility: hidden;
}

.supervision-kpis .kpi-card:not([data-tooltip-dismissed]):is(:hover, :focus) .supervision-kpi-tooltip {
  visibility: visible;
}

.supervision-filters {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
}

.filter-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-3);
  align-items: end;
}

/* A secondary action that shares the filter row without adding a new line. */
.filter-row__action {
  display: flex;
  justify-content: flex-end;
  justify-self: end;
}

.filter-row--primary {
  /* The three fields share the full row: search keeps a wider share and the
     administrative-state selector uses the space freed by the removed checks. */
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr);
}

.admin-inventory-filters {
  container-type: inline-size;
}

/* Below the desktop breakpoint the three fields keep sharing one row with
   equal widths so long origin and state labels stay readable. */
@container (max-width: 760px) {
  .admin-inventory-filters .filter-row--primary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* On the narrowest containers each field takes the full width and stacks
   without truncating its label or select value. */
@container (max-width: 520px) {
  .admin-inventory-filters .filter-row--primary {
    grid-template-columns: minmax(0, 1fr);
  }
}

.supervision-filters--plant {
  container-type: inline-size;
}

.supervision-filters__controls {
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1.4fr) minmax(0, 1.15fr)
    repeat(2, minmax(0, 0.85fr)) minmax(0, 1.25fr) auto auto;
}

.supervision-filters__controls .filter-field,
.supervision-filters__controls .checkbox-field {
  font-size: 0.85rem;
}

.supervision-filters__controls .checkbox-field input {
  flex-shrink: 0;
}

@container (max-width: 1020px) {
  .supervision-filters__controls {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@container (max-width: 620px) {
  .supervision-filters__controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@container (max-width: 380px) {
  .supervision-filters__controls {
    grid-template-columns: minmax(0, 1fr);
  }
}

.filter-field {
  display: grid;
  gap: var(--space-1);
  font-weight: 800;
}

.filter-field--checkbox {
  justify-items: start;
  font-weight: 600;
}

.filter-field--checkbox input[type="checkbox"] {
  width: 18px;
  min-width: 18px;
  min-height: 18px;
  height: 18px;
  padding: 0;
  justify-self: start;
}

.filter-field input,
.filter-field select,
.filter-field textarea,
.filter-field option,
.filter-field + select,
.supervision-filters select {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--color-text);
}

.filter-field input:disabled {
  color: var(--color-muted);
  background: #edf2f0;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 40px;
  font-weight: 800;
}

.filter-details summary {
  width: max-content;
  min-height: 36px;
  cursor: pointer;
  font-weight: 800;
}

.result-count {
  margin: 0;
  font-size: 0.92rem;
}

.machine-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr));
  grid-auto-rows: minmax(min-content, auto);
  align-content: start;
  gap: var(--space-3);
  align-items: stretch;
  max-height: min(68vh, 760px);
  overflow: auto;
  padding: var(--space-1);
}

.machine-card {
  position: relative;
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 6px;
  grid-template-rows: var(--machine-card-row-0, auto) var(--machine-card-row-1, auto)
    var(--machine-card-row-2, auto) var(--machine-card-row-3, auto)
    var(--machine-card-row-4, auto) var(--machine-card-row-5, auto)
    var(--machine-card-row-6, auto) var(--machine-card-row-7, auto);
  min-height: 0;
  padding: var(--space-3) var(--space-2);
  text-align: left;
  border: 1px solid var(--color-border);
  border-left-width: 6px;
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-surface);
}

.machine-card:hover {
  transform: translateY(-1px);
}

.machine-card.is-selected {
  border-width: 1px;
  border-left-width: 6px;
  box-shadow: 0 0 0 3px rgba(27, 103, 216, 0.18), 0 12px 28px rgba(21, 33, 30, 0.12);
}

.machine-card.is-stale {
  opacity: 0.68;
}

.machine-card.is-changed {
  animation: card-highlight 1.8s ease-out 1;
}

.machine-card--moving {
  border-left-color: var(--color-ok);
}

.machine-card--stopped {
  border-left-color: var(--color-danger);
  background: #fff7f7;
}

.machine-card--counter_gap,
.machine-card--no_communication {
  border-left-color: var(--color-warning);
  background: #fff9ec;
}

.machine-card--operational_disconnected {
  border-left-color: var(--color-warning);
  background: #fff9ec;
}

.machine-card--waiting_signal {
  border-left-color: var(--color-focus);
  background: #f4f8ff;
}

.machine-card--disabled {
  border-left-color: var(--color-muted);
  background: #f4f6f5;
}

.machine-card__top {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 4px;
  min-width: 0;
}

.machine-card__top > * {
  min-width: 0;
  overflow-wrap: normal;
}

.machine-card__identity {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.machine-card__identity > strong {
  flex-shrink: 0;
  white-space: nowrap;
}

.machine-card__state {
  display: inline-flex;
  min-width: 0;
  max-width: 100%;
  align-items: center;
  gap: var(--space-1);
  font-weight: 800;
}

.machine-card__pending {
  position: absolute;
  right: var(--space-2);
  top: var(--space-3);
  display: inline-grid;
  flex: 0 0 1.5rem;
  width: 1.5rem;
  height: 1.5rem;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  opacity: 0.85;
}

/* The fixed-size slot keeps the card footprint stable as pending toggles. */
.machine-card__pending.is-hidden {
  visibility: hidden;
}

.state-glyph {
  display: grid;
  flex: 0 0 24px;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 0.82rem;
}

.machine-card__metrics {
  display: contents;
}

.machine-card__metrics > span {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 2px 8px;
  min-width: 0;
}

.machine-card__metrics small {
  flex: 1 1 8rem;
  min-width: 0;
  font-size: 0.75rem;
  line-height: 1.4;
}

.machine-card__metrics b {
  flex: 0 0 auto;
  margin-left: auto;
  font-size: 0.875rem;
  white-space: nowrap;
  text-align: right;
  line-height: 1.4;
}

.machine-card__name {
  display: flex;
  flex-wrap: wrap;
  align-content: start;
  align-items: baseline;
  gap: 4px 8px;
  overflow-wrap: anywhere;
}

.machine-card__state > span:last-child {
  overflow-wrap: normal;
  white-space: nowrap;
}

/* The stop confidence is a single-line status, never a wrapped paragraph. */
.machine-card__confidence {
  min-width: 0;
  white-space: nowrap;
}

.machine-card__metrics small,
.machine-card__foot {
  color: var(--color-muted);
}

.machine-card__foot {
  font-size: 0.82rem;
  line-height: 1.4;
}

.machine-card__badge {
  justify-self: start;
  padding: 2px 8px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: #fff;
  color: var(--color-muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.panel-section {
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--color-border);
}

.panel-section:first-child {
  padding-top: 0;
}

.panel-section:last-child {
  border-bottom: 0;
}

.panel-section h3 {
  margin: 0 0 var(--space-3);
}

.panel-section dl,
.detail-row {
  display: grid;
  gap: var(--space-2);
}

.detail-row {
  grid-template-columns: minmax(110px, 0.75fr) minmax(0, 1fr);
}

.detail-row dt {
  color: var(--color-muted);
  font-weight: 800;
}

.detail-row dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.panel-action {
  width: 100%;
  margin-top: var(--space-4);
}

.event-list {
  display: grid;
  gap: var(--space-3);
  padding-left: 1.2rem;
}

.event-list li {
  display: grid;
  gap: var(--space-1);
}

.event-list small {
  color: var(--color-muted);
}

.toast-stack {
  position: fixed;
  right: var(--space-5);
  bottom: var(--space-5);
  z-index: 20;
  display: grid;
  gap: var(--space-3);
  width: min(360px, calc(100vw - 32px));
}

.toast {
  padding: var(--space-4);
  border: 1px solid #e4b3b3;
  border-left: 6px solid var(--color-danger);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow-panel);
}

.toast p {
  margin: var(--space-1) 0 0;
  color: var(--color-muted);
}

.control-view {
  align-content: start;
}

.topology-view {
  align-content: start;
}

.topology-stage {
  position: relative;
  min-height: 620px;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background:
    linear-gradient(rgba(97, 113, 108, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(97, 113, 108, 0.08) 1px, transparent 1px),
    var(--color-surface);
  background-size: 48px 48px;
  box-shadow: 0 10px 24px rgba(21, 33, 30, 0.08);
}

.topology-canvas {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  cursor: default;
}

.topology-canvas.can-pan {
  cursor: grab;
}

.topology-canvas.can-pan.is-panning {
  cursor: grabbing;
}

.topology-canvas.is-editing-layout .topology-machine {
  cursor: move;
}

.topology-canvas.is-moving-machine {
  cursor: move;
}

.topology-plane {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.topology-machine {
  position: absolute;
  width: 200px;
  height: 290px;
  transform-origin: 0 0;
}

.topology-machine.is-selected {
  outline: 4px solid var(--color-focus);
  outline-offset: 8px;
  border-radius: var(--radius);
}

.topology-controls {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  max-width: calc(100% - var(--space-5));
  gap: var(--space-2);
  align-items: center;
  padding: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow-panel);
}

.topology-control {
  min-width: 36px;
  height: 36px;
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  font-weight: 700;
  cursor: pointer;
}

.topology-control--fit {
  min-width: 112px;
  font-weight: 600;
}

.topology-control--edit[aria-pressed="true"] {
  border-color: var(--color-primary);
  background: #e8f2ef;
  color: var(--color-primary);
}

.topology-control--reset {
  min-width: 172px;
}

.topology-warning {
  padding: var(--space-3) var(--space-4);
  border: 1px solid #e8c56d;
  border-left: 5px solid #d99a00;
  border-radius: var(--radius);
  background: #fff8e4;
  color: #6b4b00;
  font-weight: 600;
}

.machine-svg {
  --machine-tone: #61716c;
  display: block;
  width: 100%;
  height: auto;
}

.machine-svg--moving { --machine-tone: #147444; }
.machine-svg--stopped { --machine-tone: #b83232; }
.machine-svg--counter_gap,
.machine-svg--no_communication { --machine-tone: #e0a000; }
.machine-svg--operational_disconnected { --machine-tone: #e0a000; }
.machine-svg--waiting_signal { --machine-tone: #1b67d8; }
.machine-svg--disabled { --machine-tone: #6b7280; }
.machine-svg--unknown { --machine-tone: #64748b; }

/* Administrative disablement neutralizes the entire drawing, including the
   halo, label and stale badge outside the body group. */
.machine-svg--disabled {
  filter: grayscale(1);
}

/* Neutralize the green-tinted metal/fabric when motion is not confirmed.
   The label retains the existing amber communication-loss indicator. */
.machine-svg--disabled .machine-svg__body,
.machine-svg--unknown .machine-svg__body,
.machine-svg--no_communication .machine-svg__body,
.machine-svg--operational_disconnected .machine-svg__body {
  filter: grayscale(1);
}

.machine-svg .ms-tone-fill { fill: var(--machine-tone); }
.machine-svg .ms-tone-glow { fill: var(--machine-tone); opacity: 0.1; }
.machine-svg .ms-shadow { fill: #15211e; opacity: 0.14; }
.machine-svg .ms-steel { fill: #9fb0ab; stroke: #6f817c; stroke-width: 0.6; }
.machine-svg .ms-steel-dark { fill: #4a5a56; }
.machine-svg .ms-steel-light { fill: #d4dfdb; }
.machine-svg .ms-cone { fill: #e8eeea; stroke: #7d8e89; stroke-width: 0.8; }
.machine-svg .ms-yarn { fill: none; stroke: #8aa09a; stroke-width: 0.8; }
.machine-svg .ms-fabric { fill: #c6d4cf; stroke: #8fa39c; stroke-width: 0.8; }
.machine-svg .ms-wales { fill: none; stroke: #8fa39c; stroke-width: 0.9; }
.machine-svg .ms-bed-edge { fill: #3b4945; }
.machine-svg .ms-bed-outline { fill: #4a5a56; }
.machine-svg .ms-bed-top { fill: #62736e; stroke: var(--machine-tone); stroke-width: 1.6; }
.machine-svg .ms-rotor-base { fill: #2f3d39; }
.machine-svg .ms-needles { fill: none; stroke: #b8c6c1; stroke-width: 2; }
.machine-svg .ms-rotor-ring { fill: none; stroke: #8fa19b; stroke-width: 1.4; }
.machine-svg .ms-core { fill: #1d2825; }
.machine-svg .ms-core-inner { fill: #2a3834; }
.machine-svg .ms-feeder-ring { fill: none; stroke: #4a5a56; stroke-width: 4; }
.machine-svg .ms-feeders { fill: none; stroke: #4a5a56; stroke-width: 2.4; stroke-linecap: round; }
.machine-svg .machine-svg__body { transition: opacity 0.2s; }
.machine-svg.is-dimmed .machine-svg__body { opacity: 0.5; }
.machine-svg .machine-svg__label-bg { fill: var(--color-surface); stroke: var(--color-border); }
.machine-svg text { text-anchor: middle; }
.machine-svg .machine-svg__code { fill: #fff; font-size: 15px; font-weight: 700; }
.machine-svg--no_communication .machine-svg__code,
.machine-svg--operational_disconnected .machine-svg__code { fill: #1b1400; }
.machine-svg .machine-svg__state { fill: var(--color-text); font-size: 12px; font-weight: 600; }
.machine-svg .machine-svg__rpm { fill: var(--color-muted); font-size: 12px; }
.machine-svg .machine-svg__stale-bg { fill: #7a4f00; }
.machine-svg .machine-svg__stale-text { fill: #fff; font-size: 9px; font-weight: 700; letter-spacing: 0.04em; }

.control-hero {
  display: flex;
  flex-wrap: wrap;
  padding: var(--space-3) var(--space-4);
  gap: var(--space-4);
  align-items: center;
  justify-content: space-between;
}

.control-hero > div {
  flex: 1 1 480px;
  min-width: 0;
}

.control-hero h1 {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 1.3rem;
}

.control-hero h1 + p {
  margin-top: var(--space-1);
  font-size: 0.875rem;
}

.control-hero > .button {
  flex: 0 0 auto;
  max-width: 100%;
}

.area-heading-icon {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  color: var(--color-accent);
}

.topology-count {
  color: var(--color-muted);
  font-weight: 700;
}

.control-section,
.confirmation-box {
  display: grid;
  gap: var(--space-4);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  box-shadow: var(--shadow-surface);
}

.control-section__header,
.control-selection-actions,
.confirmation-actions,
.operation-record__head {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  justify-content: space-between;
}

.control-selection-actions,
.confirmation-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* Selection block: title on the left, actions on the right and the cards 12 px
   below the header, with no extra text rows in between. */
.control-view .control-section.control-selection { gap: var(--space-3); }
.control-selection .control-section__header { align-items: center; }
.control-selection-actions { flex: 0 0 auto; margin-left: auto; }

.control-machine-list {
  --control-machine-height: 98px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 190px), 1fr));
  grid-auto-rows: var(--control-machine-height);
  row-gap: var(--space-3);
  column-gap: var(--space-2);
  align-content: start;
  /* The card viewport follows the window, never the number of machines. The
     reserved gutter keeps the internal scroll available with any inventory. */
  height: max(22rem, calc(100vh - 22rem));
  height: max(22rem, calc(100dvh - 22rem));
  max-height: none;
  overflow-x: hidden;
  overflow-y: scroll;
  scrollbar-gutter: stable;
  padding: 0 var(--space-1) var(--space-1);
  border-radius: var(--radius);
  background: var(--color-surface);
  box-shadow: inset 0 0 0 1px var(--color-border);
  min-width: 0;
  overflow-anchor: none;
}

.control-machine {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--space-2);
  align-items: center;
  height: var(--control-machine-height);
  min-height: var(--control-machine-height);
  min-width: 0;
  align-self: stretch;
  overflow: hidden;
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface-strong);
}

.control-machine > span {
  min-width: 0;
}

.control-machine__rpm {
  display: block;
  max-width: 100%;
  white-space: nowrap;
}

.control-machine.is-selected {
  border-color: var(--color-focus);
  box-shadow: 0 0 0 2px rgba(27, 103, 216, 0.16);
}

.control-machine.is-disabled {
  opacity: 0.62;
}

.control-machine__status {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  min-width: 0;
  overflow: hidden;
  font-size: 0.88rem;
  font-weight: 700;
}

.control-machine__status strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.control-machine__status--moving {
  color: var(--color-ok);
}

.control-machine__status--stopped {
  color: var(--color-danger);
}

.control-machine__status--disabled {
  color: var(--color-muted);
}

.control-machine__status--no_communication {
  color: var(--color-warning);
}

.control-machine__status--operational_disconnected {
  color: var(--color-warning);
}

.control-machine__status--waiting_signal {
  color: var(--color-focus);
}

.control-machine__status--unknown {
  color: var(--color-muted);
}

.control-machine__rpm {
  color: var(--color-muted);
}

.control-machine--moving {
  border-left: 4px solid var(--color-ok);
}

.control-machine--stopped {
  border-left: 4px solid var(--color-danger);
}

.control-machine--no_communication {
  border-left: 4px solid var(--color-warning);
}

.control-machine--operational_disconnected {
  border-left: 4px solid var(--color-warning);
}

.control-machine--waiting_signal {
  border-left: 4px solid var(--color-focus);
}

.control-machine--disabled {
  border-left: 4px solid var(--color-muted);
}

.control-machine__status > span {
  display: inline-grid;
  place-items: center;
  width: 1.2em;
  flex: 0 0 auto;
}

.control-machine > span {
  display: grid;
  gap: var(--space-1);
}

.control-machine small {
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

.operation-groups {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}

.operation-group {
  display: grid;
  gap: var(--space-3);
  align-content: start;
}

.operation-group h3,
.confirmation-box h2 {
  margin: 0;
}

.operation-grid {
  display: grid;
  gap: var(--space-2);
}

.operation-button {
  display: grid;
  gap: var(--space-1);
  min-height: 78px;
  padding: var(--space-3);
  text-align: left;
  border: 1px solid var(--color-border);
  border-left: 5px solid var(--color-accent);
  border-radius: var(--radius);
  background: var(--color-surface-strong);
  color: var(--color-text);
}

.operation-button--critical {
  border-left-color: var(--color-warning);
}

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

.operation-button small {
  color: var(--color-muted);
  display: block;
}

.side-panel[data-topology-machine-id] .control-rpm {
  margin-bottom: var(--space-3);
}

.control-rpm {
  max-width: 260px;
}

.control-view .control-section {
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  min-width: 0;
}

/* The section gap already separates the title from its content. */
.control-view .control-section > h2 { margin-bottom: 0; }

/* Selected machine: identity, state, detection and speeds share one compact
   informative line above the controls. */
.control-current {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
  min-width: 0;
}

.control-current__separator { color: var(--color-muted); }
.control-current__code { font-size: 1.15rem; }
.control-current__confidence { min-width: 0; white-space: nowrap; }
.control-current__state {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px 10px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 0.85rem;
  line-height: 1.5;
}
.control-current__rpm { font-size: 1.05rem; }
.control-primary-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: var(--space-2);
  min-width: 0;
}
.control-primary-actions > .operation-button { flex: 1 1 9rem; }
.control-speed-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(4.5rem, 7.75rem);
  gap: var(--space-2);
  flex: 1 1 17rem;
  min-width: 0;
}
.control-speed-action .control-rpm { display: flex; align-items: stretch; margin: 0; }
.control-speed-action .control-rpm input { width: 100%; min-width: 0; }
.control-view .operation-button strong {
  white-space: normal;
  overflow-wrap: normal;
  word-break: normal;
}
.control-view .operation-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 6px 14px;
  font-size: 0.86rem;
  text-align: center;
}
.control-view .operation-button--start { border-left-color: var(--color-ok); }
.control-view .operation-button--stop { border-left-color: var(--color-danger); }
.control-batch { border-left: 5px solid var(--color-warning); }
/* Batch heading and its machines share one line; the actions start directly
   below it, with no intermediate row of empty space. */
.control-batch__header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-1) var(--space-3);
  min-width: 0;
}
.control-batch__header h2 { margin: 0; }
.control-batch__selection { margin: 0; overflow-wrap: anywhere; }
/* Temporary one-line result of the last order; it fades out and is removed by
   the control live sync or by its own animation end. */
.control-notice {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  padding-top: var(--space-2);
  border-top: 1px solid var(--color-border);
  font-size: 0.9rem;
  white-space: nowrap;
  animation: control-notice-expire 8s ease-in forwards;
}
.control-notice__text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.control-notice--rejected { color: var(--color-danger); }
.control-notice--uncertain { color: var(--color-warning); }
@keyframes control-notice-expire {
  0%, 80% { opacity: 1; }
  100% { opacity: 0; visibility: hidden; }
}

@media (max-width: 760px) {
  .control-current__separator { display: none; }
}
@media (max-width: 520px) {
  .app-shell:has(.control-view) .topbar { position: static; }
}
.confirmation-box {
  border-color: #e5c56f;
  background: #fffaf0;
}

/* Compact one-line confirmation: action, affected machines and the decision. */
.confirmation-box--strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-2) var(--space-4);
}

.confirmation-strip {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-1) var(--space-3);
  min-width: 0;
  margin: 0;
}

.confirmation-strip strong {
  font-size: 0.95rem;
  white-space: nowrap;
}

.confirmation-strip__targets {
  color: var(--color-muted);
  overflow-wrap: anywhere;
}

.confirmation-box--strip .confirmation-actions {
  flex: 0 0 auto;
  flex-wrap: nowrap;
  margin-left: auto;
}

.confirmation-box--strip .button {
  min-height: 32px;
  padding: 4px 12px;
}

.confirmation-dialog {
  width: min(480px, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  margin: auto;
  overflow: auto;
  color: var(--color-text);
  box-shadow: var(--shadow-panel);
}

.confirmation-dialog:not([open]) {
  display: none;
}

.confirmation-dialog::backdrop {
  background: rgba(21, 33, 30, 0.45);
}

/* Session operations: a compact table; without records the message and the
   always-visible pagination share one footer row. */
.control-view .control-section.control-history {
  gap: var(--space-3);
  padding: var(--space-4);
}
.control-history .control-section__header { align-items: start; }
.control-history h2 { margin-bottom: 0; }
.control-view .control-section.control-history--empty {
  padding-top: var(--space-2);
  padding-bottom: var(--space-2);
}

/* Shared table footer: Administration → Máquinas registradas is the reference
   pattern and Control reuses the same HTML and CSS. */
.table-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2) var(--space-3);
}
.table-footer .pagination-controls { flex: 0 1 auto; }
.admin-table-wrap.operation-history { max-height: min(46vh, 560px); }
.admin-table.operation-history-table { min-width: 560px; }
.operation-history-table th { white-space: nowrap; }
.operation-history-table td { vertical-align: top; }
.operation-history-table .operation-record > td:first-child {
  border-left: 4px solid var(--color-accent);
}
.operation-history-table .operation-record--rejected > td:first-child,
.operation-history-table .operation-record--failed > td:first-child,
.operation-history-table .operation-record--unknown > td:first-child,
.operation-history-table .operation-record--uncertain > td:first-child {
  border-left-color: var(--color-danger);
}
.operation-history-table .operation-record--partial > td:first-child {
  border-left-color: var(--color-warning);
}
.operation-history-table .operation-record--success > td:first-child,
.operation-history-table .operation-record--confirmed > td:first-child {
  border-left-color: var(--color-ok);
}
.operation-record__head {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.operation-record__head time {
  color: var(--color-muted);
  font-size: 0.78rem;
  white-space: nowrap;
}
.operation-history-table .operation-outcome { margin: 0; }
.operation-history-table .operation-message { margin: 0; overflow-wrap: anywhere; }
.operation-history-table .operation-warning { margin: 4px 0 0; }
.operation-history-table .operation-results { margin-top: 4px; }
.operation-history-table .event-list { margin: 0; padding-left: 1.2rem; }
.operation-history-table .event-list li { overflow-wrap: anywhere; }

/* Last command result in the Administration/Topology control panel. Status,
   command and operation id stay together; the read-result action keeps its
   own column and moves below the information when the panel is narrow. */
.operation-feedback {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  min-width: 0;
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid var(--color-border);
}

.operation-feedback__info {
  display: grid;
  gap: var(--space-1);
  flex: 1 1 17rem;
  min-width: 0;
}

.operation-feedback__info > * {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.operation-feedback__id {
  color: var(--color-muted);
  font-size: 0.85rem;
}

.operation-feedback > .button {
  flex: 0 0 auto;
  max-width: 100%;
  min-height: 36px;
  padding: 6px 14px;
  margin-left: auto;
  white-space: normal;
  overflow-wrap: anywhere;
}

.operation-warning {
  margin: 0;
  color: var(--color-danger);
  font-weight: 800;
}

.operation-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: var(--space-2);
  margin: 0;
}

.operation-meta div {
  display: grid;
  gap: var(--space-1);
}

.operation-meta dt {
  color: var(--color-muted);
  font-weight: 800;
}

.operation-meta dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.operation-results {
  margin: 0;
}

.admin-view {
  align-content: start;
}

.admin-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
}

.admin-tab {
  min-height: 40px;
  padding: 0 var(--space-3);
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--color-muted);
  font-weight: 800;
}

.admin-tab.is-active,
.admin-tab:hover {
  border-color: var(--color-border);
  background: #e1efec;
  color: var(--color-accent-strong);
}

.admin-capabilities,
.admin-section {
  display: grid;
  gap: var(--space-4);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  box-shadow: var(--shadow-surface);
}

.admin-section { gap: var(--space-3); }

.admin-capabilities h2,
.admin-section h2 {
  margin: 0;
}

/* One stable place for the single machine-integration flow. */
.admin-integration-slot {
  display: grid;
  gap: var(--space-4);
}

.admin-integration-slot:empty {
  display: none;
}

.admin-table-wrap {
  max-height: min(58vh, 680px);
  overflow: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.admin-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  background: var(--color-surface);
}

.admin-table th,
.admin-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  vertical-align: middle;
}

.admin-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--color-surface);
  color: var(--color-muted);
  font-size: 0.86rem;
  text-transform: uppercase;
}

.admin-table tr:last-child td {
  border-bottom: 0;
}

.admin-table tr.is-selected td {
  background: #f0f6ff;
}

.analysis-section[aria-labelledby="stops-title"] td:nth-child(2),
.analysis-section[aria-labelledby="events-title"] td:nth-child(2) {
  white-space: nowrap;
}

.table-link {
  min-height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--color-accent-strong);
  cursor: pointer;
  font-weight: 900;
  text-decoration: underline;
}

.admin-form {
  display: grid;
  gap: var(--space-3);
}

.admin-form--inline {
  grid-template-columns: minmax(150px, 1fr) minmax(140px, 180px) minmax(170px, 1fr) auto;
  align-items: end;
}

.admin-action-grid,
.admin-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* Administration → Gestionar and Confidence → Ver parada are the same side
   panel: shared body constraints, stacked detail rows, field widths, two-column
   action grid and button metrics. Keep both selectors together so neither
   drifts into a panel of its own. */
.side-panel[data-admin-panel-key^="admin-machine-detail:"] .side-panel__body,
.side-panel.confidence-detail .side-panel__body {
  min-width: 0;
  overflow-wrap: anywhere;
}
.side-panel[data-admin-panel-key^="admin-machine-detail:"] .detail-row {
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-1);
}
.side-panel[data-admin-panel-key^="admin-machine-detail:"] .detail-row dd {
  font-weight: 600;
}
.side-panel[data-admin-panel-key^="admin-machine-detail:"] .admin-form,
.side-panel[data-admin-panel-key^="admin-machine-detail:"] .filter-field,
.side-panel.confidence-detail .admin-form,
.side-panel.confidence-detail .filter-field {
  min-width: 0;
}
.side-panel[data-admin-panel-key^="admin-machine-detail:"] input,
.side-panel.confidence-detail input,
.side-panel.confidence-detail textarea {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.side-panel.confidence-detail textarea {
  resize: vertical;
}
.side-panel[data-admin-panel-key^="admin-machine-detail:"] .admin-action-grid,
.side-panel.confidence-detail .admin-action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: var(--space-3) 0;
}
@media (max-width: 520px) {
  .side-panel.confidence-detail .panel-section:has(.confidence-form) {
    padding-top: var(--space-2);
  }
  .side-panel.confidence-detail .confidence-form .admin-action-grid {
    margin-top: 0;
  }
}
.side-panel[data-admin-panel-key^="admin-machine-detail:"] .button,
.side-panel.confidence-detail .button {
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
  padding: var(--space-2) var(--space-3);
}
/* The machine editor restores its own scroll after each live update. Native
   anchoring would adjust it again when a pending-order block appears. */
.side-panel[data-admin-panel-key^="admin-machine-detail:"] {
  overflow-anchor: none;
}
.admin-machine-details > h3 {
  margin-bottom: var(--space-3);
}
.side-panel[data-admin-panel-key^="admin-machine-detail:"] .button:disabled,
.side-panel.confidence-detail .button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
/* The administrative editor ends at the last control button: the nested
   section adds no padding or divider, and each button is one compact line. */
.admin-machine-details .panel-section {
  padding: 0;
  border: 0;
}
.admin-machine-details .operation-grid { gap: var(--space-2); }
.admin-machine-details .operation-button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 6px 14px;
  text-align: center;
}
.admin-machine-details .control-rpm { margin-bottom: var(--space-2); }

.pending-operation {
  display: grid;
  gap: var(--space-1);
  margin: var(--space-3) 0;
  padding: var(--space-2) var(--space-3);
  border-left: 4px solid var(--color-warning);
  border-radius: 6px;
  background: var(--color-surface-strong);
}

.pending-operation h4,
.pending-operation p {
  margin: 0;
}

.pending-operation small {
  color: var(--color-muted);
  overflow-wrap: anywhere;
}

.admin-uncertain__form {
  margin-top: var(--space-3);
}

.json-block {
  max-height: 280px;
  overflow: auto;
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: #101c19;
  color: #eef8f5;
  font-size: 0.82rem;
  white-space: pre-wrap;
}

.analysis-view {
  align-content: start;
}

.analysis-section > *,
.analysis-chart > * {
  min-width: 0;
}

.analysis-section,
.analysis-chart,
.analysis-export {
  display: grid;
  gap: var(--space-4);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  box-shadow: var(--shadow-surface);
}

.analysis-section h2,
.analysis-chart h3,
.analysis-export h2 {
  margin: 0;
}

.analysis-export {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.analysis-export__technical {
  grid-column: 1 / -1;
  padding-top: var(--space-2);
  border-top: 1px solid var(--color-border);
}

.analysis-export__technical > summary {
  width: fit-content;
  cursor: pointer;
  color: var(--color-muted);
  font-size: 0.82rem;
}

.analysis-export__technical[open] > summary {
  margin-bottom: var(--space-2);
}

.notice--warning {
  border-color: #e5c56f;
  background: #fffaf0;
}

.notice--ok {
  border-color: #add9c3;
  background: #f4fbf7;
}

.status-icon--warning {
  background: #f6e8bd;
  color: var(--color-warning);
}

.status-icon--ok {
  background: #d8f0e4;
  color: var(--color-ok);
}

.bar-chart {
  display: flex;
  align-items: end;
  gap: var(--space-1);
  min-height: 160px;
  min-width: 0;
  overflow-x: auto;
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface-strong);
}

.bar-item {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  flex: 1 0 24px;
  min-width: 24px;
  height: 140px;
  align-items: end;
  gap: var(--space-1);
  text-align: center;
}

.bar {
  display: block;
  min-height: 4px;
  border-radius: 4px 4px 0 0;
  background: var(--color-accent);
}

.bar-item small {
  color: var(--color-muted);
  font-size: 0.72rem;
}

.horizontal-bars {
  display: grid;
  gap: var(--space-2);
  overflow-x: auto;
}

.horizontal-bar {
  display: grid;
  grid-template-columns: minmax(130px, 0.5fr) minmax(0, 1fr);
  gap: var(--space-3);
  align-items: center;
}

.horizontal-bar span {
  color: var(--color-muted);
  font-weight: 800;
}

.horizontal-bar b {
  display: block;
  min-width: 32px;
  padding: 4px 8px;
  border-radius: var(--radius);
  background: var(--color-accent);
  color: #fff;
  text-align: right;
}

/* Analysis · historical summary dashboard */
.analysis-filters {
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
}

.analysis-filters .filter-row--primary {
  grid-template-columns: minmax(170px, 1.35fr) minmax(150px, 1fr) minmax(140px, 0.9fr) auto;
}

.analysis-filters .filter-row--advanced {
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
}

.analysis-summary {
  display: grid;
  gap: var(--space-3);
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.analysis-summary__header,
.analysis-panel__header {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  align-items: end;
  justify-content: space-between;
}

.analysis-summary__header h2,
.analysis-panel h3 {
  margin: 0;
}

.analysis-summary__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  margin: 0;
  color: var(--color-muted);
  font-size: 0.86rem;
}

.analysis-summary__meta strong {
  color: var(--color-text);
}

.analysis-kpis {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-2);
}

.analysis-kpis .kpi-card {
  min-height: 0;
  gap: 2px;
  padding: 10px 12px;
  box-shadow: none;
}

.analysis-kpis .kpi-card strong {
  font-size: 1.45rem;
}

.analysis-kpis .kpi-card small {
  font-size: 0.72rem;
  line-height: 1.2;
}

.analysis-kpis .kpi-card__label {
  font-size: 0.74rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.analysis-summary-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
  gap: var(--space-3);
  align-items: start;
}

.analysis-panel {
  display: grid;
  gap: var(--space-2);
  min-width: 0;
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  box-shadow: var(--shadow-surface);
}

.analysis-panel--wide {
  grid-column: 1 / -1;
}

.analysis-subtitle {
  margin: 0;
  color: var(--color-muted);
  font-size: 0.8rem;
}

.analysis-panel .admin-table-wrap {
  max-height: none;
}

.analysis-panel .admin-table {
  min-width: 0;
}

.analysis-ranking .admin-table {
  min-width: 320px;
}

.analysis-panel .admin-table th,
.analysis-panel .admin-table td {
  padding: 6px 8px;
  font-size: 0.8rem;
}

.analysis-total {
  margin: 0;
  color: var(--color-text);
  font-size: 0.84rem;
  font-weight: 800;
}

.analysis-panel .horizontal-bar {
  grid-template-columns: minmax(110px, 0.55fr) minmax(0, 1fr);
  gap: var(--space-2);
}

.analysis-panel .horizontal-bar b {
  padding: 2px 6px;
  font-size: 0.75rem;
}

.analysis-details summary {
  width: max-content;
  min-height: 30px;
  cursor: pointer;
  font-weight: 800;
}

.analysis-sort {
  all: unset;
  display: inline-flex;
  gap: 4px;
  align-items: center;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
}

.analysis-sort:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.analysis-sort__direction {
  color: var(--color-muted);
  font-size: 0.82em;
}

th[aria-sort="ascending"] .analysis-sort,
th[aria-sort="descending"] .analysis-sort {
  color: var(--color-accent);
}

.analysis-ranking .pagination-controls {
  justify-content: space-between;
}

@media (max-width: 1100px) {
  .analysis-kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .analysis-summary-grid {
    grid-template-columns: minmax(0, 1fr);
  }

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

  .analysis-filters .filter-row--primary .button {
    justify-self: start;
  }
}

@media (max-width: 620px) {
  .analysis-kpis {
    grid-template-columns: minmax(0, 1fr);
  }

  .analysis-ranking .admin-table th,
  .analysis-ranking .admin-table td {
    padding: 6px 4px;
  }

  .analysis-ranking .admin-table {
    min-width: 300px;
  }

  .analysis-summary__header {
    align-items: start;
  }

  .analysis-filters .filter-row--primary {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Analysis · administrative dashboard */
.analysis-view {
  gap: var(--space-4);
}

.analysis-hero {
  align-items: center;
}

.analysis-hero .section-kicker {
  margin-bottom: 2px;
}

.analysis-controls {
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
}

.analysis-controls__primary {
  display: grid;
  grid-template-columns: minmax(170px, 1.2fr) minmax(160px, 1fr) max-content auto auto;
  gap: var(--space-3);
  align-items: end;
}

.analysis-controls__primary .filter-field {
  min-width: 0;
}

.analysis-export-actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.analysis-export-actions .button {
  margin-top: 0;
  white-space: nowrap;
}

.analysis-dashboard {
  display: grid;
  gap: var(--space-3);
  min-width: 0;
}

.analysis-kpis--primary .kpi-card {
  min-height: 108px;
  padding: 14px 16px;
}

.analysis-kpis--primary .kpi-card strong {
  font-size: 1.85rem;
}

.analysis-kpis--primary .kpi-card small {
  font-size: 0.78rem;
}

.analysis-machine-table .analysis-situation {
  display: inline-block;
  padding: 2px 8px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  color: var(--color-muted);
  font-size: 0.76rem;
  white-space: nowrap;
}

.analysis-machine-table .analysis-situation--attention {
  border-color: #e5c56f;
  background: #fffaf0;
  color: var(--color-warning);
}

/* Reasons use the same table as the attention ranking above. The semantic
   green/amber reading is a discrete dot, never a horizontal bar. */
.analysis-reason-cell {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
  min-width: 0;
}

.analysis-reason-label {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 700;
}

.analysis-reason-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--color-ok);
}

.analysis-reason-dot--pending { background: var(--color-warning); }

.analysis-reason-cell .analysis-situation {
  font-size: 0.72rem;
}

/* Same left alignment as the attention table; durations stay complete. */
.analysis-reason-table th:last-child,
.analysis-reason-table td:last-child,
.analysis-reason-table th:nth-child(2),
.analysis-reason-table td:nth-child(2) {
  white-space: nowrap;
}

.analysis-quality {
  display: grid;
  gap: var(--space-3);
  min-width: 0;
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-muted);
  border-radius: var(--radius);
  background: var(--color-surface-strong);
}

.analysis-quality__header {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  align-items: end;
  justify-content: space-between;
}

.analysis-quality__header h2 {
  margin: 0;
}

.analysis-quality__summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-2);
}

.analysis-quality__summary > div {
  display: grid;
  gap: 1px;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
}

.analysis-quality__summary span {
  color: var(--color-muted);
  font-size: 0.74rem;
  font-weight: 700;
}

.analysis-quality__summary strong {
  font-size: 1.2rem;
  line-height: 1.2;
}

.analysis-quality__summary small {
  color: var(--color-muted);
  font-size: 0.72rem;
}

.analysis-quality__states h3,
.analysis-quality__details h3 {
  margin: 0 0 var(--space-2);
  font-size: 0.92rem;
}

.analysis-quality__stack {
  display: flex;
  width: 100%;
  height: 14px;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
}

.analysis-quality__segment {
  display: block;
  height: 100%;
}

.analysis-quality__segment--confirmed,
.analysis-quality__dot--confirmed {
  background: var(--color-accent);
}

.analysis-quality__segment--probable,
.analysis-quality__dot--probable {
  background: var(--color-warning);
}

.analysis-quality__segment--indeterminate,
.analysis-quality__dot--indeterminate {
  background: var(--color-muted);
  opacity: 0.7;
}

.analysis-quality__segment--invalidated,
.analysis-quality__dot--invalidated {
  background: var(--color-danger);
}

.analysis-quality__segment--unknown,
.analysis-quality__dot--unknown {
  background: var(--color-border);
}

.analysis-quality__legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--space-1) var(--space-4);
  margin: var(--space-2) 0 0;
  padding: 0;
  list-style: none;
}

.analysis-quality__legend li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  gap: var(--space-2);
  align-items: center;
  min-width: 0;
  font-size: 0.8rem;
}

.analysis-quality__legend li > span:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.analysis-quality__legend strong {
  white-space: nowrap;
}

.analysis-quality__legend small {
  color: var(--color-muted);
  white-space: nowrap;
}

.analysis-quality__dot {
  display: block;
  width: 9px;
  height: 9px;
  border-radius: 999px;
}

.analysis-quality__note,
.analysis-quality__pending {
  margin: 0;
  color: var(--color-muted);
  font-size: 0.78rem;
}

.analysis-quality__pending {
  color: var(--color-warning);
  font-weight: 700;
}

.analysis-quality__details {
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-2);
}

.analysis-quality__details > summary {
  width: max-content;
  min-height: 30px;
  cursor: pointer;
  color: var(--color-muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.analysis-quality__detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr);
  gap: var(--space-4);
  /* The shorter block sits on the same bottom edge as the state table. */
  align-items: end;
  margin-top: var(--space-2);
}

.analysis-quality__coverage {
  margin: 0;
}

.analysis-detail {
  display: grid;
  gap: var(--space-3);
  min-width: 0;
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  box-shadow: var(--shadow-surface);
}

.analysis-detail__header {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: flex-start;
  justify-content: space-between;
}

.analysis-detail__header h2 {
  margin: 0;
}

.analysis-detail__toolbar {
  display: flex;
  flex: 0 0 auto;
  justify-content: flex-end;
}

.analysis-detail__toolbar .filter-field {
  min-width: 190px;
}

.analysis-row-action {
  padding: 5px 10px;
  font-size: 0.76rem;
  white-space: nowrap;
}

.analysis-detail__body {
  min-width: 0;
}

/* The shared pagination keeps the Administration footer spacing instead of
   sitting against the table; the card padding supplies the bottom margin. */
.analysis-detail__footer {
  margin-top: var(--space-4);
}

.analysis-technical {
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-2);
}

.analysis-technical > summary {
  width: max-content;
  min-height: 30px;
  cursor: pointer;
  color: var(--color-muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.analysis-technical dl {
  margin-top: var(--space-2);
}

@media (max-width: 1100px) {
  .analysis-controls__primary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .analysis-controls__primary .analysis-export-actions {
    justify-self: start;
  }

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

  .analysis-quality__detail-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 760px) {
  .analysis-quality__summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .analysis-detail__header {
    align-items: start;
  }
}

@media (max-width: 620px) {
  .analysis-controls__primary {
    grid-template-columns: minmax(0, 1fr);
  }

  .analysis-controls__primary .button,
  .analysis-controls__primary .analysis-export-actions {
    justify-self: stretch;
  }

  .analysis-export-actions {
    width: 100%;
  }

  .analysis-export-actions .button {
    flex: 1 1 0;
  }

  .analysis-quality {
    padding: var(--space-3);
  }

  .analysis-quality__summary,
  .analysis-quality__legend {
    grid-template-columns: minmax(0, 1fr);
  }

  .analysis-detail {
    padding: var(--space-3);
  }

  .analysis-detail__toolbar {
    flex: 1 1 100%;
    justify-content: stretch;
  }

  .analysis-detail__toolbar .filter-field {
    width: 100%;
  }

  .analysis-machine-table thead,
  .analysis-reason-table thead,
  .analysis-detail__table-grid thead {
    display: none;
  }

  .analysis-machine-table,
  .analysis-machine-table tbody,
  .analysis-machine-table tr,
  .analysis-machine-table td,
  .analysis-reason-table,
  .analysis-reason-table tbody,
  .analysis-reason-table tr,
  .analysis-reason-table td,
  .analysis-detail__table-grid,
  .analysis-detail__table-grid tbody,
  .analysis-detail__table-grid tr,
  .analysis-detail__table-grid td {
    display: block;
    width: 100%;
  }

  .analysis-detail .analysis-detail__table-grid,
  .analysis-detail .analysis-detail__table-grid tbody,
  .analysis-detail .analysis-detail__table-grid tr,
  .analysis-detail .analysis-detail__table-grid td {
    min-width: 0;
  }

  .analysis-detail .admin-table-wrap {
    max-height: none;
    overflow: visible;
  }

  .analysis-machine-table tr,
  .analysis-reason-table tr,
  .analysis-detail__table-grid tr {
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--color-border);
  }

  .analysis-machine-table td,
  .analysis-reason-table td,
  .analysis-detail__table-grid td {
    display: flex;
    gap: var(--space-2);
    justify-content: space-between;
    padding: 3px var(--space-2);
    border: 0;
    text-align: right;
  }

  .analysis-machine-table td::before,
  .analysis-reason-table td::before,
  .analysis-detail__table-grid td::before {
    content: attr(data-label);
    flex: 0 0 42%;
    color: var(--color-muted);
    font-weight: 700;
    text-align: left;
  }

  /* Stacked reason rows fill the card and keep their values right-aligned. */
  .analysis-reason-table td:nth-child(2),
  .analysis-reason-table th:last-child,
  .analysis-reason-table td:last-child {
    width: 100%;
    text-align: right;
  }

}

.pagination-controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
  justify-content: flex-end;
}

.pagination-controls span {
  color: var(--color-muted);
  font-weight: 800;
}

.pagination-size {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-muted);
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
}

.pagination-size select {
  min-height: 38px;
  padding: 0 var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
  color: var(--color-ink);
}

.pagination-controls--compact {
  display: grid;
  grid-template-areas:
    "previous next"
    "status size";
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.95fr);
  gap: var(--space-2);
  width: 100%;
}

.pagination-controls--compact .pagination-controls__previous {
  grid-area: previous;
}

.pagination-controls--compact .pagination-controls__next {
  grid-area: next;
}

.pagination-controls--compact .pagination-controls__status {
  grid-area: status;
  min-width: 0;
  align-self: center;
  overflow-wrap: anywhere;
  font-size: 0.85rem;
}

.pagination-controls--compact .pagination-controls__size {
  display: grid;
  grid-area: size;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--space-1);
  min-width: 0;
  align-items: center;
  font-size: 0.8rem;
}

.pagination-controls--compact .pagination-controls__size select {
  width: 100%;
  min-width: 0;
}

.admin-operation-feedback {
  margin: 0;
  padding: var(--space-2) var(--space-3);
  border-left: 4px solid var(--color-accent);
  border-radius: 6px;
  background: var(--color-surface-strong);
}

.admin-operation-feedback--success {
  border-left-color: var(--color-ok);
}

.admin-operation-feedback--error,
.admin-operation-feedback--conflict,
.admin-operation-feedback--rejected,
.admin-operation-feedback--failed {
  border-left-color: var(--color-danger);
}

.operation-results > summary {
  cursor: pointer;
  color: var(--color-accent-strong);
  font-weight: 800;
}

.operation-results ol {
  max-height: 260px;
  overflow: auto;
  padding-left: 1.3rem;
}

@keyframes card-highlight {
  0% {
    box-shadow: 0 0 0 0 rgba(184, 50, 50, 0.28);
  }

  100% {
    box-shadow: 0 0 0 14px rgba(184, 50, 50, 0);
  }
}

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

@media (min-width: 1180px) {
  .dashboard-layout:has(.side-panel) {
    grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
  }

  /* The topology detail is the only side panel that should use the full
     remaining height: its information and controls are read together. The
     panel remains the single scroll container; the page and the panel never
     chase each other. */
  .side-panel[data-topology-machine-id] {
    max-height: calc(100vh - 7rem);
    max-height: calc(100dvh - 7rem);
  }
}

@media (max-width: 820px) {
  .topbar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .topbar__nav {
    justify-content: start;
    overflow-x: auto;
    padding-bottom: var(--space-1);
  }

  .topbar__actions {
    justify-content: start;
    flex-wrap: wrap;
  }

  .connection-pill {
    flex: 1 1 220px;
  }

  .dashboard-layout {
    padding: var(--space-3);
  }

  .control-hero,
  .control-section__header,
  .operation-groups,
  .admin-form--inline,
  .horizontal-bar,
  .analysis-export {
    grid-template-columns: 1fr;
  }

  .control-hero,
  .control-section__header {
    display: grid;
    align-items: start;
  }

  .side-panel {
    position: fixed;
    inset: auto var(--space-3) var(--space-3);
    z-index: 30;
    max-height: min(78vh, 680px);
    overflow: auto;
  }
}

@media (max-width: 520px) {
  .auth-shell {
    padding: var(--space-3);
  }

  .login-card,
  .workspace-card {
    padding: var(--space-4);
  }

  .topbar {
    padding: var(--space-3);
  }

  .button--secondary {
    flex: 1 1 auto;
  }

  .workspace-card.control-hero,
  .workspace-card.topology-header {
    padding: var(--space-3) var(--space-4);
  }

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

  .pagination-controls {
    justify-content: start;
  }

  .pagination-controls .button {
    flex: 1 1 42%;
  }

  .pagination-controls--compact .button {
    min-width: 0;
    flex: initial;
    padding: 0 var(--space-2);
    white-space: normal;
  }

  .pagination-controls [role="status"] {
    flex: 1 1 100%;
  }

  .pagination-controls--compact [role="status"] {
    flex: initial;
  }

  .pagination-size {
    flex: 1 1 100%;
    justify-content: space-between;
  }

  .pagination-controls--compact .pagination-controls__size {
    flex: initial;
  }

  /* Shared table footer: the counter takes one line and the controls stay on
     the following line, right aligned. */
  .table-footer .pagination-controls {
    justify-content: flex-end;
    gap: var(--space-2);
    width: 100%;
  }
  .table-footer .pagination-controls [role="status"] {
    order: -1;
    flex: 1 1 100%;
  }
  .table-footer .pagination-controls .button {
    flex: 0 1 auto;
    min-width: 0;
  }
  .table-footer .pagination-size {
    flex: 0 0 auto;
    justify-content: flex-start;
  }

  .pagination-controls--compact {
    grid-template-areas:
      "status status"
      "previous next"
      "size size";
  }

  .toast-stack {
    right: var(--space-3);
    bottom: var(--space-3);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
  }
}

.analysis-stop-open,
.analysis-classification-pending {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  white-space: nowrap;
}

.analysis-classification-pending {
  border-color: #e5c56f;
  background: #fffaf0;
}

.analysis-classification-form textarea {
  resize: vertical;
}

.analysis-view .filter-field,
.analysis-view .filter-field input,
.analysis-view .filter-field select {
  min-width: 0;
}

@media (max-width: 520px) {
  .analysis-view .filter-row {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Control · scalable scheduled-scenario target picker */
.scenario-targets {
  display: grid;
  gap: var(--space-2);
  min-width: 0;
}

.scenario-target-controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: end;
  justify-content: space-between;
}

.scenario-search {
  flex: 1 1 240px;
  min-width: 0;
}

.scenario-selection-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.scenario-selection-summary {
  margin: 0;
  color: var(--color-text-muted, #59636d);
  font-weight: 600;
}

.scenario-target-list {
  display: grid;
  gap: 1px;
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--color-border, #d8dee4);
  border-radius: var(--radius-sm, 6px);
}

.scenario-target {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  padding: 0.35rem 0.6rem;
  background: var(--color-surface, #fff);
}

.scenario-target__code {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.scenario-target__name {
  color: var(--color-text-muted, #59636d);
  overflow-wrap: anywhere;
}

.scenario-catalog-entry {
  display: grid;
  gap: 0.2rem;
  margin-bottom: var(--space-2);
}

.scenario-catalog-entry small {
  color: var(--color-text-muted, #59636d);
}

@media (max-width: 520px) {
  .scenario-target {
    grid-template-columns: auto minmax(0, 1fr);
  }
  .scenario-target__name {
    grid-column: 2;
  }
}

.event-information {
  display: block;
  max-width: 52ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Health uses observation states; industrial state colours/animations are independent. */
.health-view { min-width: 0; gap: var(--space-4); }
.health-view section, .health-view article, .health-view table { min-width: 0; overflow-wrap: anywhere; }
.health-system-card { overflow: hidden; }
.health-view h2 { margin: 0 0 var(--space-3); }
.health-status { font-weight: 700; display: inline-block; }
.health-status--operational { color: var(--color-ok); }
.health-status--recovering { color: var(--color-info); }
.health-status--degraded { color: var(--color-warning); }
.health-status--blocked { color: var(--color-danger); }
.health-status--unavailable { color: var(--color-danger); }
.health-status--unknown { color: var(--color-muted); }
.health-view .detail-row { grid-template-columns: minmax(140px, 0.7fr) minmax(0, 1.3fr); gap: var(--space-3); }
.health-view .detail-row > * { min-width: 0; max-width: 100%; }
/* ESP32 consultation reuses the Administration filter controls. */
.health-device-filters { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); margin-block: var(--space-4); }
.health-device-filters .filter-field { min-width: 0; }
.health-device-filters input,
.health-device-filters select { min-height: 44px; max-width: 100%; }
.health-view button, .health-view select { min-height: 44px; }
.health-view .pagination-controls { flex-wrap: wrap; margin-block: var(--space-3); justify-content: flex-start; }
.health-view .notice { margin-block: var(--space-3); }
@media (max-width: 520px) {
  .health-view .pagination-controls { flex-direction: column; align-items: stretch; }
  .health-view .workspace-card { padding: var(--space-3); }
  .health-view .detail-row { grid-template-columns: minmax(0,1fr); gap: 2px; }
}
@media (max-width: 820px) {
  .dashboard-shell:has(.health-view) .topbar__nav { flex-wrap: nowrap; }
  .dashboard-shell:has(.health-view) .topbar__nav .nav-link { flex-shrink: 0; }
}


/* Salud: lectura directa y pantalla técnica sin desplegables. */
.health-system-card, .health-summary-card, .health-device-card { box-shadow:none; border-top:3px solid var(--color-border); }
/* Resumen: componentes a la izquierda y almacenamiento a la derecha, con
   bordes superior e inferior alineados y apilado en pantallas estrechas. */
.health-summary-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:16px; align-items:stretch; }
.health-summary-card { display:flex; flex-direction:column; min-width:0; padding:var(--space-3) var(--space-4); }
/* The taller card fixes the row height; the shorter one spreads its own rows
   over the remaining space instead of leaving a blank area below. The storage
   card always renders its five indicators, so an even share keeps them
   balanced instead of leaving the last row disproportionately tall. */
.health-summary-card > .health-table { flex:1 1 auto; }
.health-storage-card > .health-table tbody tr { height:20%; }
.health-storage-card > .health-table tbody td { vertical-align:middle; }
@media (max-width:1024px) {
  .health-summary-grid { grid-template-columns:minmax(0,1fr); }
}
.health-table { width:100%; border-collapse:collapse; font-size:.875rem; table-layout:fixed; }
.health-table th, .health-table td { padding:8px; text-align:left; vertical-align:top; border-bottom:1px solid var(--color-border); }
.health-table small { display:block; }
.health-view > .notice { margin:0; }
@media(max-width:520px) {
  .health-table thead { display:none; }
  .health-table, .health-table tbody, .health-table tr, .health-table td { display:block; width:100%; }
  .health-table tr { padding:8px 0; border-bottom:1px solid var(--color-border); }
  .health-table td { border:0; padding:4px 0; }
  .health-table td::before { content:attr(data-label); display:block; font-weight:600; }
}

/* Salud: overview and secondary technical screen. */
.health-primary { display:grid; gap:12px; }
.health-primary[hidden], .health-technical[hidden] { display:none; }
.health-navigation { display:flex; flex-wrap:wrap; align-items:center; gap:8px; }
.health-navigation [aria-pressed="true"] { border-color:var(--color-accent); font-weight:700; }
/* The technical screen shows both cards as one aligned grid. Both keep the
   same fixed height, so their top and bottom borders stay aligned while the
   device page (10, 7, 1 or 0 rows) changes. The tables scroll inside the card
   and the pagination remains pinned to the bottom. */
.health-technical { --health-technical-card-height:660px; display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:16px; align-items:stretch; }
.health-technical > .workspace-card {
  display:flex; flex-direction:column; height:var(--health-technical-card-height); overflow:hidden;
}
.health-technical > .workspace-card > h2,
.health-technical > .workspace-card > p,
.health-technical > .workspace-card > form { flex:0 0 auto; }
.health-table-scroll,
.health-device-results { flex:1 1 auto; min-height:0; overflow:auto; }
.health-device-consult > .pagination-controls { flex:0 0 auto; margin:var(--space-2) 0 0; }
@media (max-width:1024px) {
  .health-technical { grid-template-columns:minmax(0,1fr); }
  .health-technical > .workspace-card { height:auto; overflow:visible; }
  .health-table-scroll,
  .health-device-results { overflow:visible; }
  .health-device-consult > .pagination-controls { margin-block:var(--space-3); }
}

/* Compact ESP32 summary: one strip with the heading and the three
   communication counters; the detailed consultation lives in Historial. */
.health-device-card {
  display:grid; grid-template-columns:auto minmax(0,1fr); align-items:center;
  gap:var(--space-4); padding:var(--space-2) var(--space-4);
}
.health-device-card h2 { margin:0; }
.health-device-card h2 .muted { font-size:.875rem; font-weight:600; }
.health-device-counts { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:var(--space-2); }
.health-device-count { display:flex; align-items:baseline; gap:var(--space-2); padding:var(--space-1) var(--space-3); background:var(--color-surface-strong); border-radius:8px; }
.health-device-count strong { font-size:1.2rem; line-height:1.2; }
.health-device-table td { overflow-wrap:anywhere; }
@media (max-width:640px) {
  .health-device-card { grid-template-columns:minmax(0,1fr); gap:var(--space-2); }
}

/* Compact overview: server states stay visible independently inside each group. */
.health-coverage { display:flex; flex-wrap:wrap; gap:6px 20px; padding:4px 0; font-size:.875rem; }
.health-attention { font-weight:700; color:var(--color-danger); }
/* A real but non-critical degradation: visible, never the red affected count. */
.health-warning { font-weight:600; color:var(--color-warning); }
.health-system-table th:last-child, .health-system-table td:last-child { width:34%; }
.health-system-table .health-group-heading th { padding:10px 12px; background:var(--color-surface-strong); font-size:.875rem; text-align:left; }
.health-system-table .health-component strong { font-size:.875rem; }
.health-system-table .health-component .health-status { font-size:.875rem; }
.health-system-table .health-component p { font-size:.875rem; margin:4px 0 0; color:var(--color-muted); }
@media (max-width:520px) {
  .health-system-table th:last-child, .health-system-table td:last-child { width:100%; }
  .health-system-table .health-group-heading th { display:block; }
  .health-system-table .health-component td:first-child::before { content:none; }
}
/* Tables retain compact rows and proportion their columns inside the grid. */
.health-table p { margin:0; }
.health-component-table th:nth-child(1) { width:26%; }
.health-component-table th:nth-child(2) { width:16%; }
.health-component-table th:nth-child(3) { width:58%; }
.health-component-table th, .health-component-table td { padding:6px 8px; overflow-wrap:anywhere; }
.health-technical .health-component-table th:nth-child(1) { width:36%; }
.health-technical .health-component-table th:nth-child(2) { width:22%; }
.health-technical .health-component-table th:nth-child(3) { width:42%; }
.health-technical .health-device-table th:nth-child(1) { width:32%; }
.health-technical .health-device-table th:nth-child(2) { width:22%; }
.health-technical .health-device-table th:nth-child(3) { width:26%; }
.health-technical .health-device-table th:nth-child(4) { width:20%; }
@media(max-width:820px) {
  .health-component-table th:nth-child(1) { width:32%; }
  .health-component-table th:nth-child(2) { width:20%; }
  .health-component-table th:nth-child(3) { width:48%; }
  .health-technical .health-component-table th:nth-child(1) { width:32%; }
  .health-technical .health-component-table th:nth-child(2) { width:20%; }
  .health-technical .health-component-table th:nth-child(3) { width:48%; }
}
.health-navigation > button { font-size:.875rem; padding:8px 12px; }

.health-device-table .health-signal { white-space:nowrap; font-size:.8rem; }

/* Confidence reuses the analysis panels, filters, tables and form controls. */
.confidence-view { align-content: start; }
.confidence-view .button:disabled { opacity: 0.5; cursor: not-allowed; }
/* Four filter fields plus the reset action share the desktop row. */
.confidence-view .filter-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) auto; }
.confidence-view .filter-field, .confidence-view input, .confidence-view select { min-width: 0; width: 100%; }
/* The review panel body, form fields and action grid come from the shared
   Administration panel rules. Its facts are a compact list: one label/value
   pair per line, so the review actions stay inside the initial panel height. */
.panel-section .confidence-facts { display: grid; gap: var(--space-1); margin: 0; }
.confidence-facts .detail-row {
  grid-template-columns: minmax(76px, max-content) minmax(0, 1fr);
  align-items: baseline;
}
.confidence-facts dd { overflow-wrap: anywhere; }
.confidence-review .event-list { margin: 0; }
.confidence-review li { min-width: 0; overflow-wrap: anywhere; }
.confidence-review__comment {
  margin: 0;
  max-width: 100%;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
@media (max-width: 760px) {
  .confidence-view .filter-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .confidence-view .filter-row__action { grid-column: 1 / -1; }
  .confidence-table thead { display: none; }
  .confidence-table, .confidence-table tbody, .confidence-table tr, .confidence-table td { display: block; width: 100%; }
  .confidence-table tr { border-bottom: 1px solid var(--color-border); padding: var(--space-2) 0; }
  .confidence-table td { border: 0; padding: var(--space-1) var(--space-2); white-space: normal; }
  .confidence-table td[data-label]::before { content: attr(data-label); display: inline-block; width: 6rem; font-weight: 600; }
  .confidence-view .admin-table { min-width: 0; }
}
@media (max-width: 440px) {
  .confidence-view .filter-row { grid-template-columns: minmax(0, 1fr); }
}
