/* Keep every SDA-specific layout and indicator style inside the Apex package. */
.apex-systeme-ui {
  --vendor-accent: var(--blue-600);
  --device-progress: 0%;
}

body.device-sidebar-open {
  overflow: hidden;
}

.apex-sidebar-toggle {
  position: fixed;
  z-index: 180;
  top: max(160px, calc(env(safe-area-inset-top) + 136px));
  left: 0;
  width: 38px;
  min-width: 38px;
  height: 72px;
  min-height: 72px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(110, 231, 183, 0.72);
  border-left: 0;
  border-radius: 0 14px 14px 0;
  background: linear-gradient(180deg, var(--navy-800), var(--navy-950));
  padding: 0 5px 0 0;
  opacity: 0.7;
  box-shadow: 8px 10px 24px rgba(7, 26, 44, 0.3);
  touch-action: manipulation;
}

.apex-sidebar-toggle:hover {
  opacity: 0.94;
  background: linear-gradient(180deg, #20577f, var(--navy-900));
}

.apex-sidebar-toggle:focus-visible {
  opacity: 1;
  outline: 3px solid rgba(110, 231, 183, 0.58);
  outline-offset: 3px;
}

/* Draw the book-tab direction marker without requiring an image asset. */
.apex-sidebar-toggle-chevron {
  width: 16px;
  height: 16px;
  display: block;
  border-right: 3px solid #6ee7b7;
  border-bottom: 3px solid #6ee7b7;
  transform: translateX(-2px) rotate(-45deg);
  filter: drop-shadow(0 2px 4px rgba(110, 231, 183, 0.38));
}

.apex-device-workspace {
  position: relative;
}

.apex-primary-content {
  min-width: 0;
}

/* Slide the complete information panel from the left on compact screens. */
.apex-device-sidebar {
  position: fixed;
  z-index: 200;
  inset: 0 auto 0 0;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  border-right: 1px solid var(--slate-300);
  background: #e9f1f7;
  color: var(--slate-900);
  box-shadow: 18px 0 48px rgba(7, 26, 44, 0.24);
  transform: translateX(-100%);
  visibility: hidden;
  transition: transform 220ms ease, visibility 220ms step-end;
}

.apex-device-sidebar.is-open {
  transform: translateX(0);
  visibility: visible;
  transition: transform 220ms ease, visibility 0ms step-start;
}

.apex-sidebar-scrim {
  position: fixed;
  z-index: 190;
  inset: 0;
  min-height: 0;
  border-radius: 0;
  background: rgba(7, 26, 44, 0.48);
  padding: 0;
}

.apex-sidebar-scrim[hidden] {
  display: none;
}

.apex-sidebar-header {
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid #aebfcd;
  background: #d8e6f1;
  padding: max(16px, env(safe-area-inset-top)) 16px 14px;
}

.apex-sidebar-header h2 {
  font-size: 21px;
}

.apex-sidebar-close {
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  border: 1px solid #9fb2c2;
  border-radius: 50%;
  background: white;
  color: #000000;
  padding: 0;
  font-size: 28px;
  font-weight: 450;
  line-height: 1;
}

.apex-sidebar-scroll {
  height: calc(100dvh - 82px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

/* Divide the dense technical information into scannable blocks. */
.apex-sidebar-block {
  border-bottom: 1px solid #aebfcd;
  background: rgba(255, 255, 255, 0.48);
  padding: 12px;
}

.apex-sidebar-block h3 {
  margin: 0 0 9px;
  color: var(--navy-900);
  font-size: 13px;
  font-weight: 850;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.apex-sidebar-row {
  min-height: 29px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(96px, 1.1fr);
  align-items: center;
  gap: 10px;
  border-top: 1px solid rgba(174, 191, 205, 0.58);
  padding: 5px 0;
}

.apex-sidebar-label {
  color: var(--slate-700);
  font-size: 12px;
  line-height: 1.25;
}

/* Visual value class stays independent from each functional read class. */
.Sidebar_Value {
  min-width: 0;
  color: var(--navy-950);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
  text-align: right;
  overflow-wrap: anywhere;
}

.Sidebar_Value.device-value-loading,
.Sidebar_Value.device-value-warning {
  color: var(--amber-700);
}

.Sidebar_Value.device-value-stale,
.Sidebar_Value.device-value-error {
  color: var(--red-700);
}

/* Build the opening meter from a track and a CSS-variable-driven fill. */
.apex-door-progress {
  --device-progress: 0%;
}

.apex-door-progress-track {
  height: 20px;
  overflow: hidden;
  border: 2px solid #23384b;
  border-radius: 5px;
  background: #aeb8c2;
}

.apex-door-progress-fill {
  width: var(--device-progress);
  height: 100%;
  background: linear-gradient(90deg, #148d4a, #31c96d);
  transition: width 180ms ease;
}

.apex-door-progress-value,
.apex-door-progress-limits {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 7px;
  color: var(--slate-700);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.apex-door-progress-value strong {
  color: var(--green-700);
  font-size: 13px;
}

.apex-door-progress-limits {
  color: var(--slate-500);
  font-size: 10px;
}

/* Keep register headings close to their exact CANopen source. */
.apex-bitfield + .apex-bitfield {
  margin-top: 13px;
}

.apex-bitfield-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  color: var(--slate-700);
  font-size: 11px;
  font-weight: 750;
}

.apex-bitfield-heading code {
  color: var(--slate-500);
  font-size: 9px;
  font-weight: 650;
}

.apex-bitfield-meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.apex-bitfield-meta output {
  min-width: 26px;
  border-radius: 999px;
  background: rgba(16, 42, 67, 0.09);
  color: var(--navy-900);
  padding: 2px 5px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 9px;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.apex-bit-grid {
  display: grid;
  grid-template-columns: repeat(8, 25px);
  gap: 5px;
}

/* Every register bit is exactly 25 by 25 pixels with a black border. */
.apex-bit {
  width: 25px;
  height: 25px;
  display: grid;
  place-items: center;
  border: 1px solid #000000;
  border-radius: 3px;
  background: #a9b0b7;
  color: #17212b;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 8px;
  font-weight: 900;
  line-height: 1;
  user-select: none;
}

.apex-bitfield--input .apex-bit.is-active,
.apex-bitfield--hall .apex-bit.is-active {
  background: #28bf62;
  color: #071a0d;
}

.apex-bitfield--output .apex-bit.is-active {
  background: #e2413a;
  color: #ffffff;
}

.apex-bitfield--status .apex-bit.is-active {
  background: #315fd3;
  color: #ffffff;
}

/*
 * Shared stale values use a strike-through, but applying that decoration to a
 * container propagates through every bit label. Bitfields use a border/status
 * message instead so their register data always remains legible.
 */
.apex-bitfield.device-value-warning,
.apex-bitfield.device-value-stale,
.apex-bitfield.device-value-error {
  border-left: 3px solid var(--amber-700);
  color: inherit;
  padding-left: 7px;
  text-decoration: none;
}

.apex-bitfield.device-value-error {
  border-left-color: var(--red-700);
}

.apex-bitfield.device-value-warning .apex-bit,
.apex-bitfield.device-value-stale .apex-bit,
.apex-bitfield.device-value-error .apex-bit {
  opacity: 0.78;
}

.apex-bitfield-status {
  margin: 6px 0 0;
  color: var(--amber-700);
  font-size: 10px;
  font-weight: 750;
  line-height: 1.25;
}

.apex-bitfield-status[hidden] {
  display: none;
}

/* Tablets use a half-width panel, matching the main hamburger-menu behavior. */
@media (min-width: 600px) and (max-width: 1099px) {
  .apex-device-sidebar {
    width: 50vw;
    min-width: 360px;
  }
}

/* Laptop and desktop layouts keep the sidebar permanently visible on the left. */
@media (min-width: 1100px) {
  body.device-sidebar-open {
    overflow: auto;
  }

  .apex-systeme-ui {
    margin-inline: calc((100vw - min(1180px, 100vw - 32px)) / -2);
  }

  .apex-device-workspace {
    display: grid;
    grid-template-columns: minmax(300px, 330px) minmax(0, 1fr);
    align-items: start;
    gap: 16px;
  }

  .apex-device-sidebar {
    position: sticky;
    z-index: 1;
    top: 110px;
    width: auto;
    height: calc(100vh - 126px);
    min-height: 520px;
    overflow: hidden;
    transform: none;
    visibility: visible;
    border: 1px solid #aebfcd;
    border-radius: 13px;
    box-shadow: 0 12px 32px rgba(15, 42, 66, 0.11);
    transition: none;
  }

  .apex-sidebar-header {
    min-height: 68px;
    padding: 12px;
  }

  .apex-sidebar-header h2 {
    font-size: 18px;
  }

  .apex-sidebar-scroll {
    height: calc(100% - 68px);
  }

  .apex-sidebar-toggle,
  .apex-sidebar-close,
  .apex-sidebar-scrim {
    display: none !important;
  }
}
