.app-root {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  --panel-width: min(420px, calc(100vw - 40px));
}

.dashboard {
  position: absolute;
  inset: 0;
  overflow: hidden;
  padding: 18px;
}

.manage-toggle {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(6, 13, 24, 0.82);
  color: var(--text);
  box-shadow: var(--shadow);
  z-index: 15;
}

.auto-refresh-toggle {
  position: absolute;
  top: 74px;
  right: 18px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(6, 13, 24, 0.82);
  color: var(--text);
  box-shadow: var(--shadow);
  z-index: 15;
}

.auto-refresh-toggle.is-disabled {
  background: rgba(239, 68, 68, 0.16);
  border-color: rgba(239, 68, 68, 0.28);
}

.auto-refresh-toggle__icon {
  font-size: 1.3rem;
  line-height: 1;
}

.manage-toggle.is-active {
  background: rgba(249, 115, 22, 0.22);
  border-color: rgba(249, 115, 22, 0.4);
}

.manage-toggle__icon {
  font-size: 1.4rem;
  line-height: 1;
}

.management-panel {
  position: absolute;
  top: 18px;
  right: 18px;
  bottom: 18px;
  width: var(--panel-width);
  overflow: hidden;
  border-radius: 0;
  transform: translateX(calc(100% + 24px));
  opacity: 0;
  pointer-events: none;
  transition: transform 180ms ease, opacity 180ms ease;
  z-index: 12;
}

.app-root.is-managing .management-panel {
  transform: translateX(0);
  opacity: 1;
  pointer-events: none;
}

.management-panel__content {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0;
  pointer-events: none;
}

.management-panel__content > * {
  pointer-events: auto;
}

.management-panel__content > *,
.panel-section,
.section-heading,
.section-heading > *,
.entity-item,
.entity-meta,
.entity-meta > *,
.card-list__header,
.card-list__meta,
.field,
.form-grid--two > * {
  min-width: 0;
}

.management-panel__header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 14px;
  padding: 18px;
}

.management-panel__header-tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 12px;
  align-items: start;
}

.management-panel__header h2 {
  margin-top: 6px;
  font-size: 1.35rem;
}

.panel-section {
  padding: 18px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0;
  border-left: 0;
  border-right: 0;
}

.section-heading {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.panel-section.is-collapsed .section-heading {
  margin-bottom: 0;
}

.section-heading h3 {
  margin-bottom: 0;
  font-size: 1.1rem;
}

.panel-section__toggle {
  width: 40px;
  height: 40px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  border-radius: 0;
  font-size: 1.45rem;
  font-weight: 700;
  line-height: 1;
}

.panel-section__toggle:hover {
  background: rgba(255, 255, 255, 0.08);
}

.section-heading--compact {
  margin-bottom: 0;
}

.section-heading--compact h5 {
  margin: 0 0 4px;
  font-size: 0.98rem;
}

.entity-list {
  display: grid;
  gap: 10px;
}

.entity-item {
  display: grid;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-small);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.entity-item.is-active {
  border-color: rgba(249, 115, 22, 0.45);
  box-shadow: inset 0 0 0 1px rgba(249, 115, 22, 0.25);
}

.entity-item.is-linked:not(.is-active) {
  border-color: rgba(20, 184, 166, 0.38);
  box-shadow: inset 0 0 0 1px rgba(20, 184, 166, 0.2);
}

.entity-meta {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
}

.entity-meta strong {
  display: block;
  margin-bottom: 4px;
}

.entity-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.entity-item--card {
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
}

.entity-item--device {
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
}

.card-list__header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
}

.card-list__meta {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
}

.card-list__chip {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.78rem;
  color: var(--muted);
}

.entity-caption,
.canvas-help,
.card-empty,
.device-empty {
  font-size: 0.88rem;
  color: var(--muted);
}

.entity-caption--truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-form {
  display: grid;
  gap: 16px;
}

.device-editor {
  display: none;
  gap: 12px;
  padding-top: 6px;
}

.device-editor.is-open {
  display: grid;
}

.device-editor h4 {
  margin: 0;
  font-size: 0.98rem;
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.dynamic-config {
  display: grid;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius-small);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.device-template-section,
.device-measurements {
  display: grid;
  gap: 12px;
  padding: 14px;
  border-radius: 0;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.form-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.18), transparent);
}

.form-divider[hidden],
.device-template-section[hidden] {
  display: none;
}

.catalog-preview {
  display: grid;
  gap: 12px;
  padding: 14px;
  border-radius: 0;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.catalog-preview[hidden] {
  display: none;
}

.catalog-preview__header {
  display: grid;
  gap: 4px;
}

.catalog-preview__measurements {
  display: grid;
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
}

.catalog-preview__measurement {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.catalog-preview__measurement strong {
  display: block;
  margin-bottom: 3px;
}

.catalog-preview__measurement code {
  font-family: Consolas, "Cascadia Code", monospace;
  font-size: 0.78rem;
  color: var(--muted);
}

.catalog-preview__measurement-meta {
  flex-shrink: 0;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: right;
}

.device-measurements__list {
  display: grid;
  gap: 10px;
}

.device-measurements__empty {
  padding: 10px 0;
}

.device-measurement-table {
  width: 100%;
  border-collapse: collapse;
}

.device-measurement-table th,
.device-measurement-table td {
  padding: 8px 6px;
  vertical-align: top;
}

.device-measurement-table th {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-align: left;
}

.device-measurement-table thead tr {
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.device-measurement-table tbody tr + tr {
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.device-measurement-table td:first-child,
.device-measurement-table th:first-child {
  padding-left: 0;
}

.device-measurement-table td:last-child,
.device-measurement-table th:last-child {
  padding-right: 0;
  width: 54px;
}

.device-measurement-row td input {
  margin: 0;
}

.device-measurement-row__actions {
  text-align: right;
}

.device-measurement-row {
  align-items: top;
}

.measurement-builder {
  display: grid;
  gap: 10px;
}

.measurement-row {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr) minmax(90px, 0.55fr) auto;
  gap: 10px;
  align-items: end;
}

.form-grid--two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.form-actions--between {
  justify-content: space-between;
  align-items: center;
}

.form-actions__group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.card {
  position: absolute;
  min-width: 250px;
  background: rgba(7, 17, 31, 0.8);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card.is-dragging {
  cursor: grabbing;
  transform: scale(1.01);
}

.card.is-selected {
  border-color: rgba(249, 115, 22, 0.48);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.32), 0 0 0 1px rgba(249, 115, 22, 0.35);
}

.card.is-linked:not(.is-selected) {
  border-color: rgba(20, 184, 166, 0.44);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.32), 0 0 0 1px rgba(20, 184, 166, 0.3);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent);
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  cursor: grab;
}

.card.is-dragging .card-header {
  cursor: grabbing;
}

.card-title {
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.card-heading {
  min-width: 0;
}

.card-subtitle {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 4px;
}

.card-header__aside {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.card-timestamp {
  font-size: 0.76rem;
  color: var(--muted);
  white-space: nowrap;
}

.card-tools {
  display: none;
  gap: 8px;
}

.card.is-editable .card-tools {
  display: flex;
}

.icon-btn {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.icon-btn:hover {
  border-color: rgba(249, 115, 22, 0.32);
}

.icon-btn--danger {
  color: #fecaca;
  border-color: rgba(239, 68, 68, 0.24);
  background: rgba(239, 68, 68, 0.12);
}

.icon-btn--danger:hover {
  border-color: rgba(239, 68, 68, 0.4);
}

.card-body {
  padding: 18px;
}

.reading-main {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-top: 8px;
}

.value-xl {
  font-size: clamp(2.5rem, 4vw, 4.6rem);
  line-height: 1;
  font-weight: 800;
  letter-spacing: -0.05em;
}

.unit-xl {
  color: var(--muted);
  font-weight: 700;
}

.status-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.pill {
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.82rem;
  color: #d7e4f2;
}

.measurement-list,
.bar-list,
.stat-grid {
  display: grid;
  gap: 12px;
}

.measurement-item,
.bar-row {
  display: grid;
  gap: 10px;
}

.measurement-item {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
}

.measurement-label,
.bar-label,
.stat-label {
  color: var(--muted);
}

.measurement-value,
.bar-value,
.stat-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.bar-row {
  grid-template-columns: 68px minmax(0, 1fr) auto;
  align-items: center;
}

.bar-track {
  height: 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
}

.stat-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stat-tile {
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.stat-value {
  font-size: clamp(1.4rem, 2.8vw, 2.3rem);
}

.stat-reading {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-top: 8px;
}

.stat-unit {
  font-size: 0.92rem;
  color: var(--muted);
  font-weight: 700;
}

.card-error {
  padding: 14px;
  border-radius: 16px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.22);
  color: #fecaca;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(3, 8, 15, 0.68);
  z-index: 20;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  width: min(760px, calc(100vw - 40px));
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding: 18px;
}

.modal--device {
  width: min(920px, calc(100vw - 40px));
}

.modal__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

@media (max-width: 1280px) {
  .app-root.is-managing .dashboard {
    right: 0;
  }
}

@media (max-width: 900px) {
  .management-panel {
    top: 12px;
    right: 12px;
    bottom: 12px;
    width: calc(100vw - 24px);
  }

  .dashboard {
    padding: 12px;
  }

  .auto-refresh-toggle {
    top: 68px;
    right: 12px;
  }

  .card {
    position: relative;
    inset: auto;
    width: 100% !important;
  }

  .card-header {
    align-items: start;
  }

  .card-header__aside {
    flex-direction: column;
    align-items: end;
  }

  .form-grid--two,
  .measurement-row {
    grid-template-columns: 1fr;
  }

  .card-list__meta {
    flex-wrap: wrap;
  }

  .modal {
    width: calc(100vw - 24px);
    max-height: calc(100vh - 24px);
  }

  .form-actions--between {
    justify-content: flex-start;
  }
}