:root {
  --bg: #07131d;
  --panel: #0c1b27;
  --panel-2: #102330;
  --panel-soft: #122a38;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #f5fbff;
  --muted: #87a2b5;
  --muted-2: #658195;
  --accent: #00b0e5;
  --accent-soft: rgba(0, 176, 229, 0.13);
  --success: #4ed49a;
  --warning: #f5bd58;
  --danger: #ff6f78;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.25);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% -10%, rgba(0, 176, 229, 0.14), transparent 32rem),
    radial-gradient(circle at 95% 0%, rgba(0, 176, 229, 0.07), transparent 28rem),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 76px;
  padding: 14px clamp(18px, 4vw, 56px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  background: rgba(7, 19, 29, 0.86);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(0, 176, 229, 0.28);
}

.brand-mark svg {
  width: 27px;
  stroke: none;
  fill: currentColor;
}

.eyebrow,
.section-kicker {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(17px, 2vw, 21px);
  letter-spacing: -0.02em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.backend-state,
.refresh-button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.025);
  font-size: 13px;
  font-weight: 650;
}

.status-dot,
.presence-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--warning);
  box-shadow: 0 0 0 4px rgba(245, 189, 88, 0.09);
}

.backend-state.ok .status-dot,
.device-presence.active .presence-dot {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(78, 212, 154, 0.10);
}

.backend-state.error .status-dot,
.device-presence.stale .presence-dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(255, 111, 120, 0.10);
}

.refresh-button {
  cursor: pointer;
  transition: border-color .18s ease, transform .18s ease, background .18s ease;
}

.refresh-button:hover {
  border-color: rgba(0, 176, 229, 0.45);
  background: var(--accent-soft);
}

.refresh-button:active {
  transform: translateY(1px);
}

.refresh-button svg {
  width: 17px;
}

.refresh-button.loading svg {
  animation: spin .8s linear infinite;
}

.page-content {
  width: min(1380px, calc(100% - 36px));
  margin: 0 auto;
  padding: 48px 0 56px;
}

.hero {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 30px;
  margin-bottom: 28px;
}

.hero h2,
.section-heading-row h2 {
  margin: 0;
  font-size: clamp(26px, 4vw, 40px);
  line-height: 1.1;
  letter-spacing: -0.04em;
}

.hero-copy {
  margin: 12px 0 0;
  max-width: 650px;
  color: var(--muted);
  line-height: 1.6;
}

.last-refresh {
  min-width: 185px;
  text-align: right;
}

.last-refresh span,
.last-refresh strong {
  display: block;
}

.last-refresh span {
  margin-bottom: 5px;
  color: var(--muted-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.last-refresh strong {
  color: var(--muted);
  font-size: 13px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 44px;
}

.summary-card {
  min-height: 116px;
  padding: 21px;
  display: flex;
  align-items: center;
  gap: 17px;
  background: linear-gradient(145deg, rgba(16, 35, 48, 0.94), rgba(12, 27, 39, 0.92));
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 14px 32px rgba(0,0,0,.12);
}

.summary-icon {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  flex: 0 0 46px;
  border-radius: 12px;
  color: var(--accent);
  background: var(--accent-soft);
}

.summary-icon.online {
  color: var(--success);
  background: rgba(78, 212, 154, 0.10);
}

.summary-icon svg {
  width: 24px;
}

.summary-card span,
.metric-label,
.state-label,
.update-time span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.summary-card strong {
  display: block;
  margin-top: 5px;
  font-size: 28px;
  letter-spacing: -0.04em;
}

.devices-section {
  margin-top: 12px;
}

.section-heading-row {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 20px;
}

.section-heading-row h2 {
  font-size: 29px;
}

.search-box {
  min-width: min(330px, 100%);
  height: 42px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  color: var(--muted);
  background: rgba(255,255,255,.025);
  border: 1px solid var(--border);
  border-radius: 11px;
  transition: border-color .18s ease, box-shadow .18s ease;
}

.search-box:focus-within {
  border-color: rgba(0, 176, 229, .5);
  box-shadow: 0 0 0 3px rgba(0, 176, 229, .08);
}

.search-box svg {
  width: 18px;
  flex: 0 0 18px;
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font-size: 14px;
}

.search-box input::placeholder {
  color: var(--muted-2);
}

.device-grid,
.loading-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.device-card,
.skeleton-card {
  min-height: 395px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background:
    linear-gradient(145deg, rgba(16, 35, 48, .98), rgba(10, 25, 36, .98));
  box-shadow: var(--shadow);
}

.device-card {
  position: relative;
  padding: 21px;
  overflow: hidden;
  transition: transform .2s ease, border-color .2s ease;
}

.device-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: .45;
}

.device-card:hover {
  transform: translateY(-2px);
  border-color: rgba(0,176,229,.22);
}

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

.device-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.device-id {
  margin: 0;
  font-size: 19px;
  letter-spacing: -0.02em;
}

.simulated-badge {
  padding: 4px 6px;
  color: var(--warning);
  background: rgba(245, 189, 88, 0.08);
  border: 1px solid rgba(245, 189, 88, 0.24);
  border-radius: 6px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .07em;
}

.sequence-text {
  display: block;
  margin-top: 5px;
  color: var(--muted-2);
  font-size: 11px;
}

.device-presence {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 9px;
  color: var(--muted);
  background: rgba(255,255,255,.025);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .07em;
  white-space: nowrap;
}

.soc-row {
  margin-top: 28px;
}

.soc-copy {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 10px;
}

.soc-copy span {
  color: var(--muted);
  font-size: 12px;
}

.soc-copy strong {
  font-size: 27px;
  letter-spacing: -0.04em;
}

.soc-track {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255,255,255,.06);
}

.soc-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #008bb7, var(--accent));
  transition: width .4s ease;
}

.metric-grid {
  margin-top: 26px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.metric {
  min-width: 0;
  padding: 16px 13px;
  background: rgba(255,255,255,.018);
}

.metric + .metric {
  border-left: 1px solid var(--border);
}

.metric strong {
  display: inline-block;
  margin-top: 8px;
  font-size: 20px;
  letter-spacing: -0.03em;
}

.metric small {
  margin-left: 2px;
  color: var(--muted);
  font-size: 11px;
}

.device-card-foot {
  margin-top: 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  align-items: end;
}

.device-card-foot strong {
  display: block;
  margin-top: 5px;
  font-size: 13px;
}

.update-time {
  text-align: right;
}

.details-button {
  width: 100%;
  height: 42px;
  margin-top: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 10px;
  border: 1px solid rgba(0,176,229,.28);
  background: var(--accent-soft);
  color: #a9eaff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 750;
  transition: background .18s ease, border-color .18s ease;
}

.details-button:hover {
  background: rgba(0,176,229,.19);
  border-color: rgba(0,176,229,.48);
}

.details-button svg {
  width: 16px;
}

.error-banner {
  margin-bottom: 15px;
  padding: 14px 16px;
  color: #ffd7da;
  background: rgba(255, 111, 120, .08);
  border: 1px solid rgba(255, 111, 120, .25);
  border-radius: 11px;
}

.error-banner strong,
.error-banner span {
  display: block;
}

.error-banner span {
  margin-top: 4px;
  color: #d6aeb1;
  font-size: 12px;
}

.empty-state {
  padding: 62px 20px;
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: rgba(255,255,255,.015);
}

.empty-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 15px;
  display: grid;
  place-items: center;
  color: var(--muted-2);
  border-radius: 13px;
  background: rgba(255,255,255,.035);
}

.empty-icon svg {
  width: 26px;
}

.empty-state h3 {
  margin: 0 0 7px;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
}

.skeleton-card {
  position: relative;
  overflow: hidden;
  min-height: 340px;
}

.skeleton-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 20%, rgba(255,255,255,.045) 45%, transparent 70%);
  transform: translateX(-100%);
  animation: shimmer 1.4s infinite;
}

.footer {
  min-height: 72px;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted-2);
  border-top: 1px solid var(--border);
  font-size: 11px;
}

.footer-separator {
  color: var(--accent);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes shimmer {
  to { transform: translateX(100%); }
}

@media (max-width: 1050px) {
  .device-grid,
  .loading-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
  }

  .eyebrow,
  .backend-state {
    display: none;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
  }

  .page-content {
    width: min(100% - 26px, 1380px);
    padding-top: 30px;
  }

  .hero,
  .section-heading-row {
    align-items: stretch;
    flex-direction: column;
  }

  .last-refresh {
    text-align: left;
  }

  .summary-grid {
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 34px;
  }

  .summary-card {
    min-height: 90px;
    padding: 16px 18px;
  }

  .summary-card strong {
    font-size: 23px;
  }

  .search-box {
    width: 100%;
    min-width: 0;
  }

  .device-grid,
  .loading-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 430px) {
  .topbar {
    padding-inline: 13px;
  }

  .brand-block {
    gap: 10px;
  }

  .topbar h1 {
    font-size: 15px;
  }

  .refresh-button {
    width: 40px;
    padding: 0;
    justify-content: center;
    font-size: 0;
  }

  .metric {
    padding-inline: 9px;
  }

  .metric strong {
    font-size: 18px;
  }

  .device-card-foot {
    grid-template-columns: 1fr;
  }

  .update-time {
    text-align: left;
  }
}
