.primary-action,
.secondary-action,
.icon-button,
.tab-button {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-small);
  background: #0b1016;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, color 160ms ease;
  -webkit-tap-highlight-color: transparent;
}

.primary-action:active,
.secondary-action:active,
.icon-button:active,
.tab-button:active {
  transform: translateY(1px);
}

.primary-action {
  min-height: 36px;
  padding: 0 0.85rem;
  color: #041006;
  border-color: rgba(82, 255, 104, 0.82);
  background: linear-gradient(180deg, #7dff89, #36d74d);
  font-weight: 840;
}

.primary-action:disabled {
  cursor: default;
  opacity: 0.72;
}

.secondary-action {
  min-height: 34px;
  padding: 0 0.58rem;
  color: var(--color-text);
  background: var(--color-surface-raised);
  font-size: 0.76rem;
  font-weight: 780;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  color: var(--color-text);
  font-weight: 900;
}

.tab-button {
  display: grid;
  place-items: center;
  gap: 0.12rem;
  min-width: 0;
  min-height: 48px;
  border-color: transparent;
  background: transparent;
  color: var(--color-muted);
  font-size: 0.68rem;
  font-weight: 780;
  text-transform: uppercase;
}

.tab-button > span:first-child {
  font-size: 1.05rem;
  line-height: 1;
}

.tab-button.is-active {
  color: var(--color-text);
  background: rgba(82, 255, 104, 0.12);
  border-color: rgba(82, 255, 104, 0.36);
}

.alert-rail {
  display: flex;
  gap: 0.4rem;
  min-height: 28px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 0.42rem;
  scrollbar-width: none;
}

.alert-rail::-webkit-scrollbar {
  display: none;
}

.alert-item {
  flex: 0 0 auto;
  max-width: 92vw;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: rgba(16, 22, 29, 0.88);
  color: var(--color-muted);
  padding: 0.34rem 0.55rem;
  font-size: 0.68rem;
  font-weight: 760;
  white-space: nowrap;
}

.alert-item.caution {
  border-color: rgba(255, 216, 79, 0.65);
  color: #ffe894;
  background: rgba(71, 52, 10, 0.66);
}

.alert-item.danger {
  border-color: rgba(255, 59, 50, 0.72);
  color: #ffb7b3;
  background: rgba(68, 13, 12, 0.72);
}

.alert-item.neutral {
  border-color: rgba(84, 199, 255, 0.42);
  color: #bfeaff;
}

.instrument-shell {
  position: relative;
  overflow: hidden;
  min-height: 0;
  border: 1px solid rgba(83, 96, 109, 0.46);
  border-radius: var(--radius-card);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent 34%),
    rgba(12, 16, 21, 0.92);
  box-shadow: var(--shadow-panel);
}

.instrument-shell::before {
  position: absolute;
  inset: 0;
  pointer-events: none;
  content: "";
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.026) 1px, transparent 1px);
  background-size: 22px 22px;
  opacity: 0.16;
}

.data-shell,
.command-shell {
  display: grid;
  min-height: 0;
}

.device-data-shell {
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.motor-gauge-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  min-height: 0;
  gap: 0.42rem;
  overflow: hidden;
}

.motor-status-shell {
  display: grid;
  grid-template-columns: minmax(116px, 0.48fr) minmax(0, 1fr);
  align-items: center;
  min-height: 42px;
}

.motion-data-shell {
  grid-template-rows: auto minmax(0, 38fr) minmax(0, 62fr) auto;
}

.command-shell {
  grid-template-rows: auto auto auto auto auto auto;
}

.section-heading {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.46rem 0.55rem 0;
  color: var(--color-text);
  font-size: 0.78rem;
  font-weight: 830;
}

.section-heading small {
  color: var(--color-muted);
  font-size: 0.62rem;
  font-weight: 780;
  text-transform: uppercase;
}

.readout-grid {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 0.36rem;
  min-height: 0;
  padding: 0.48rem 0.5rem;
}

.fit-readouts {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
}

.status-readouts {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.28rem;
  padding: 0.34rem 0 0.34rem 0.42rem;
}

.compact-readouts {
  padding-top: 0.36rem;
  padding-bottom: 0;
}

.readout-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.45rem;
  min-height: 0;
  border: 1px solid rgba(83, 96, 109, 0.36);
  border-radius: var(--radius-small);
  background: rgba(5, 7, 10, 0.58);
  padding: 0.36rem 0.46rem;
}

.status-readouts .readout-card {
  gap: 0.28rem;
  padding: 0.26rem 0.34rem;
}

.status-readouts .readout-card strong {
  font-size: 0.52rem;
}

.status-readouts .readout-card span {
  font-size: 0.76rem;
}

.readout-card strong {
  display: block;
  overflow: hidden;
  color: var(--color-muted);
  font-size: 0.62rem;
  font-weight: 780;
  line-height: 1.1;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.readout-card span {
  color: var(--color-text);
  font-family: var(--font-mono);
  font-size: 0.98rem;
  font-weight: 820;
  line-height: 1;
  white-space: nowrap;
}

.readout-card small {
  color: var(--color-dim);
  font-size: 0.58rem;
  font-weight: 780;
}

.readout-card span.caution {
  color: var(--color-amber);
}

.readout-card span.danger {
  color: var(--color-red);
}

.flag-strip {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem;
  align-content: start;
  min-height: 29px;
  padding: 0 0.5rem 0.48rem;
  overflow: hidden;
}

.motor-status-shell .flag-strip {
  flex-wrap: nowrap;
  min-height: 0;
  overflow-x: auto;
  padding: 0.34rem 0.42rem;
  scrollbar-width: none;
}

.motor-status-shell .flag-strip::-webkit-scrollbar {
  display: none;
}

.flag-pill {
  border: 1px solid rgba(83, 96, 109, 0.42);
  border-radius: 999px;
  background: rgba(5, 7, 10, 0.55);
  color: var(--color-dim);
  padding: 0.22rem 0.42rem;
  font-size: 0.58rem;
  font-weight: 780;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
}

.flag-pill.is-on {
  border-color: rgba(82, 255, 104, 0.42);
  color: #b7ffc0;
  background: rgba(82, 255, 104, 0.1);
}

.flag-pill.is-off {
  border-color: rgba(255, 216, 79, 0.35);
  color: #b9a969;
}

.button-row {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 0.42rem;
  padding: 0.42rem 0.5rem;
}

.command-buttons {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding-bottom: 0.22rem;
}

.command-form {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.42rem;
  padding: 0.28rem 0.5rem;
}

.command-form input {
  min-height: 36px;
  padding: 0.52rem 0.58rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

.runtime-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.75fr);
  padding-top: 0.2rem;
  padding-bottom: 0.12rem;
}

.switch-row {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 0.46rem;
}

.compact-switch {
  min-height: 30px;
  padding: 0;
}

.switch-row input {
  width: 1rem;
  height: 1rem;
  flex: 0 0 auto;
  accent-color: var(--color-green);
}

.switch-row span {
  overflow: hidden;
  color: var(--color-muted);
  font-size: 0.64rem;
  font-weight: 780;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.command-response {
  position: relative;
  z-index: 1;
  overflow: hidden;
  margin: 0.28rem 0.5rem 0;
  border: 1px solid rgba(83, 96, 109, 0.38);
  border-radius: var(--radius-small);
  background: rgba(5, 7, 10, 0.62);
  color: #bfeaff;
  padding: 0.42rem 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.is-stale .instrument-shell {
  border-color: rgba(255, 216, 79, 0.36);
}

@media (max-height: 720px) {
  .section-heading {
    padding-top: 0.34rem;
    font-size: 0.72rem;
  }

  .readout-grid {
    gap: 0.28rem;
    padding: 0.34rem 0.42rem;
  }

  .readout-card {
    padding: 0.28rem 0.38rem;
  }

  .readout-card strong {
    font-size: 0.56rem;
  }

  .readout-card span {
    font-size: 0.86rem;
  }

  .flag-strip {
    min-height: 24px;
    gap: 0.22rem;
    padding: 0 0.42rem 0.34rem;
  }

  .flag-pill {
    font-size: 0.52rem;
    padding: 0.18rem 0.34rem;
  }

  .secondary-action,
  .primary-action,
  .command-form input {
    min-height: 30px;
  }

  .command-response {
    padding: 0.34rem 0.42rem;
    font-size: 0.66rem;
  }
}
