:root {
  --panel: rgba(255, 251, 245, 0.94);
  --panel-strong: rgba(255, 255, 255, 0.84);
  --ink: #18262b;
  --muted: #61727a;
  --line: rgba(24, 38, 43, 0.12);
  --accent: #0f766e;
  --accent-dark: #0a5a54;
  --accent-soft: rgba(15, 118, 110, 0.12);
  --good: #2e7d32;
  --bad: #c62828;
  --shadow: 0 18px 36px rgba(28, 40, 45, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.16), transparent 26%),
    radial-gradient(circle at right, rgba(217, 119, 6, 0.11), transparent 20%),
    linear-gradient(180deg, #f7f2e9 0%, #efe7da 100%);
}

.layout {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.hero,
.toolbar,
.content-grid .panel,
.layout > .panel:last-child {
  padding: 20px;
}

.hero {
  display: grid;
  grid-template-columns: 1.65fr 1fr;
  gap: 18px;
  align-items: center;
  padding: 16px 20px;
  margin-bottom: 18px;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  margin-bottom: 18px;
}

.toolbar-copy h2,
h1,
h2,
h3 {
  margin: 0;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
}

h1 {
  font-size: clamp(1.7rem, 3.1vw, 2.6rem);
  line-height: 1;
}

h3 {
  margin-bottom: 10px;
  font-size: 1rem;
}

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 0.76rem;
  color: var(--accent);
}

.subtext,
.muted,
.card-label {
  color: var(--muted);
}

.detail-card,
.device-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel-strong);
}

.status-inline-button,
.stat-card strong,
.detail-card strong {
  display: block;
  margin-top: 8px;
  font-size: 1.45rem;
}

.detail-pre {
  margin: 12px 0 0;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fbfaf7;
  font-family: "IBM Plex Mono", monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.stat-card {
  padding: 18px;
}

.toolbar-controls {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
}

.status-inline-button {
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.status-inline-button strong {
  margin-top: 4px;
  font-size: 1.1rem;
}

.status-inline-button .muted {
  margin: 4px 0 0;
}

.status-inline-button:hover strong {
  color: var(--accent-dark);
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 220px;
}

select,
.secondary-button,
.danger-button,
.detail-button,
.icon-button {
  border: 1px solid var(--line);
  border-radius: 14px;
  font: inherit;
}

select {
  min-height: 46px;
  padding: 0 14px;
  background: #fffdfa;
  color: var(--ink);
}

.secondary-button,
.danger-button,
.detail-button {
  min-height: 46px;
  padding: 0 16px;
  cursor: pointer;
}

.secondary-button,
.detail-button {
  background: transparent;
  color: var(--accent-dark);
}

.danger-button {
  background: rgba(198, 40, 40, 0.08);
  color: var(--bad);
  border-color: rgba(198, 40, 40, 0.22);
}

.detail-button {
  min-height: 38px;
}

.secondary-button:hover,
.danger-button:hover,
.detail-button:hover,
.device-card:hover {
  border-color: rgba(15, 118, 110, 0.38);
  background: rgba(15, 118, 110, 0.06);
}

.danger-button:hover {
  border-color: rgba(198, 40, 40, 0.34);
  background: rgba(198, 40, 40, 0.12);
}

.content-grid {
  display: grid;
  grid-template-columns: 1.5fr 0.95fr;
  gap: 18px;
  margin-bottom: 18px;
}

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

.panel-header-stack {
  align-items: center;
}

#map {
  width: 100%;
  height: 460px;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.side-panel {
  display: flex;
  flex-direction: column;
}

.device-list {
  display: grid;
  gap: 10px;
  max-height: 460px;
  overflow: auto;
}

.device-card {
  width: 100%;
  padding: 14px;
  text-align: left;
  cursor: pointer;
}

.device-card.is-active {
  border-color: rgba(15, 118, 110, 0.6);
  box-shadow: inset 0 0 0 1px rgba(15, 118, 110, 0.18);
}

.device-card-header,
.device-card-body {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.device-card-body {
  margin-top: 8px;
  flex-direction: column;
  color: var(--muted);
  font-size: 0.92rem;
}

.records-chip {
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 0.88rem;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
}

.badge-valid {
  color: var(--good);
  background: rgba(46, 125, 50, 0.12);
}

.badge-invalid {
  color: var(--bad);
  background: rgba(198, 40, 40, 0.12);
}

.empty-state,
.empty-table {
  padding: 20px;
  color: var(--muted);
  text-align: center;
}

.detail-drawer {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 999;
}

.detail-drawer.is-open {
  display: block;
}

.detail-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 25, 28, 0.42);
}

.detail-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(560px, 100%);
  height: 100%;
  padding: 22px;
  background: #f8f5ef;
  box-shadow: -12px 0 40px rgba(17, 26, 28, 0.18);
  overflow: auto;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 14px;
  margin-bottom: 18px;
}

.icon-button {
  width: 42px;
  height: 42px;
  background: #fffdfa;
  color: var(--accent-dark);
  font-size: 1.6rem;
  cursor: pointer;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.detail-card {
  padding: 16px;
}

.detail-section + .detail-section {
  margin-top: 18px;
}

@media (max-width: 1080px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .hero,
  .toolbar,
  .content-grid {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 700px) {
  .layout {
    width: min(100% - 20px, 1280px);
  }

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

  #map {
    height: 320px;
  }

  .detail-panel {
    width: 100%;
  }

  th,
  td {
    min-width: 120px;
  }
}
