:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --text: #172026;
  --muted: #62707a;
  --line: #d8e0e5;
  --primary: #137c6b;
  --primary-dark: #0d5f52;
  --accent: #b23a48;
  --warning: #b66b00;
  --shadow: 0 12px 32px rgba(18, 35, 45, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 32px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-weight: 750;
}

h1 {
  font-size: 26px;
}

h2 {
  font-size: 17px;
}

.status-pill {
  min-width: 112px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.status-pill.ready {
  border-color: rgba(19, 124, 107, 0.24);
  color: var(--primary-dark);
  background: #e6f4f1;
}

.status-pill.error {
  border-color: rgba(178, 58, 72, 0.3);
  color: var(--accent);
  background: #fdebee;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
  gap: 20px;
  padding: 24px 32px 36px;
}

.panel,
.summary {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.controls {
  align-self: start;
  display: grid;
  gap: 16px;
  padding: 18px;
  position: sticky;
  top: 16px;
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

input:focus,
select:focus {
  border-color: var(--primary);
  outline: 3px solid rgba(19, 124, 107, 0.13);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.controls .grid-2 {
  grid-template-columns: 1fr;
}

button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-weight: 750;
}

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

.primary {
  background: var(--primary);
  color: #fff;
}

.primary:hover {
  background: var(--primary-dark);
}

.secondary,
.ghost {
  background: #fff;
  border-color: var(--line);
  color: var(--text);
}

.secondary:hover,
.ghost:hover {
  border-color: var(--primary);
  color: var(--primary-dark);
}

.ghost {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 13px;
}

.content {
  display: grid;
  gap: 20px;
}

.summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  overflow: hidden;
}

.summary > div {
  min-height: 86px;
  padding: 18px;
  border-right: 1px solid var(--line);
}

.summary > div:last-child {
  border-right: 0;
}

.metric-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.summary strong {
  display: block;
  overflow: hidden;
  font-size: 24px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.split {
  display: grid;
  grid-template-columns: minmax(300px, 0.9fr) minmax(420px, 1.1fr);
  gap: 20px;
}

.split .panel,
.content > .panel {
  padding: 18px;
}

.details-panel {
  display: grid;
  gap: 14px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.detail-grid > div {
  min-height: 68px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f9fa;
  overflow: hidden;
}

.detail-grid span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.detail-grid strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 14px;
}

.empty-detail {
  grid-column: 1 / -1;
  color: var(--muted);
}

.dp-table {
  margin-top: 2px;
}

.reading-label {
  font-weight: 750;
}

.reading-hint {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-head span {
  color: var(--muted);
  font-size: 13px;
}

.device-list {
  display: grid;
  gap: 10px;
}

.device-card {
  display: grid;
  gap: 10px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.device-card.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(19, 124, 107, 0.12);
}

.device-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.device-name {
  font-weight: 800;
}

.device-id,
.device-product {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 12px;
}

.online,
.offline {
  flex: 0 0 auto;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.online {
  background: #e6f4f1;
  color: var(--primary-dark);
}

.offline {
  background: #f5ece1;
  color: var(--warning);
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.status-item {
  min-height: 54px;
  padding: 8px;
  border-radius: 6px;
  background: #f7f9fa;
  overflow: hidden;
}

.status-item span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.status-item strong {
  display: block;
  overflow-wrap: anywhere;
  margin-top: 4px;
  font-size: 14px;
}

canvas {
  width: 100%;
  height: auto;
  display: block;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td:last-child,
th:last-child {
  text-align: right;
}

pre {
  max-height: 320px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  border-radius: 8px;
  background: #111a20;
  color: #eaf2f4;
  font-size: 13px;
  line-height: 1.5;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(440px, calc(100vw - 40px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #172026;
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 14px;
}

@media (max-width: 980px) {
  .layout,
  .split {
    grid-template-columns: 1fr;
  }

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

  .controls {
    position: static;
  }
}

@media (max-width: 620px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 20px;
  }

  .layout {
    padding: 16px;
  }

  .summary,
  .grid-2,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .summary > div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .summary > div:last-child {
    border-bottom: 0;
  }
}
