:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #17212b;
  --muted: #64717f;
  --line: #d8dee6;
  --accent: #0d766e;
  --accent-dark: #075e58;
  --warn: #b42318;
}

* {
  box-sizing: border-box;
}

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

.app {
  width: min(100%, 1240px);
  margin: 0 auto;
  padding: 16px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.7rem, 9vw, 2.7rem);
  line-height: 1.02;
}

h2 {
  font-size: 1rem;
}

.status {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.status.online {
  border-color: #b7eadf;
  color: var(--accent-dark);
}

.status.alarm {
  border-color: #f4b6ad;
  color: var(--warn);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.metrics article,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.metrics article {
  min-width: 0;
  padding: 10px 12px;
}

.metrics span,
.metrics small,
label {
  color: var(--muted);
  font-size: 0.78rem;
}

.metrics strong {
  display: block;
  margin-top: 6px;
  font-size: clamp(1.05rem, 3.2vw, 1.45rem);
  line-height: 1;
  letter-spacing: 0;
}

.metrics small {
  display: block;
  margin-top: 4px;
}

.panel {
  margin: 12px 0;
  padding: 14px;
}

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

.form-error {
  margin: 0;
  color: var(--warn);
  font-size: 0.85rem;
}

.form-hint {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

canvas {
  display: block;
  width: 100%;
  height: 220px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
}

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

label {
  display: grid;
  gap: 6px;
}

input,
select,
button {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  font: inherit;
}

button {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

button.secondary {
  border-color: var(--line);
  background: #eef2f4;
  color: var(--ink);
}

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

.navigation {
  position: sticky;
  top: 12px;
  margin-top: 0;
}

.site-list,
.device-list {
  display: grid;
  gap: 6px;
}

.navigation-heading {
  margin: 22px 0 8px;
}

.claim-device {
  margin-top: 22px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.claim-device summary {
  cursor: pointer;
  color: var(--accent-dark);
  font-weight: 700;
}

.claim-device form {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.claim-device small {
  color: var(--muted);
  line-height: 1.4;
}

.claim-feedback {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.claim-feedback.error {
  color: var(--warn);
}

.claim-feedback.success {
  color: var(--accent-dark);
}

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

.nav-item {
  min-height: 40px;
  border-color: transparent;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  border-color: #b7eadf;
  background: #e8f7f3;
  color: var(--accent-dark);
}

.device-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.device-item small {
  color: var(--muted);
  font-weight: 500;
}

.icon-button {
  width: 44px;
  padding: 8px;
}

.device-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 0;
}

.device-header[hidden],
.empty-state[hidden] {
  display: none;
}

.device-header small,
.empty-state p,
.feedback {
  color: var(--muted);
}

.dynamic-metrics {
  margin: 12px 0 0;
}

.history-toolbar {
  justify-content: flex-end;
  margin-top: 12px;
}

.history-toolbar select {
  width: min(100%, 320px);
}

.command-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.command-grid button {
  width: auto;
}

button.danger {
  border-color: #f4b6ad;
  color: var(--warn);
}

.feedback {
  min-height: 24px;
  margin: 8px 0;
}

.feedback.error {
  color: var(--warn);
}

.feedback.success {
  color: var(--accent-dark);
}

.history {
  display: grid;
  gap: 8px;
  max-height: 320px;
  margin: 12px 0 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.history li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  color: var(--muted);
  font-size: 0.85rem;
}

.history strong {
  color: var(--ink);
}

@media (max-width: 720px) {
  .app {
    padding: 12px;
  }

  .metrics,
  .grid-form {
    grid-template-columns: 1fr;
  }

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

  .navigation {
    position: static;
  }

  .site-list,
  .device-list {
    grid-auto-flow: column;
    grid-auto-columns: minmax(150px, 1fr);
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .command-grid button {
    width: 100%;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .status {
    width: max-content;
  }
}
