:root {
  color-scheme: dark;
  --bg: #050b13;
  --surface: #0b1522;
  --surface-2: #101e2d;
  --surface-3: #142639;
  --line: #20364b;
  --line-soft: rgba(126, 162, 190, 0.16);
  --text: #f1f7fb;
  --muted: #8ca2b5;
  --dim: #5d7183;
  --cyan: #52d7ff;
  --green: #38e39c;
  --yellow: #ffca5c;
  --red: #ff667c;
  --blue: #669cff;
  --radius: 18px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.24);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  background:
    radial-gradient(circle at 85% -10%, rgba(46, 154, 219, 0.16), transparent 35%),
    linear-gradient(180deg, #07111f 0, var(--bg) 420px);
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(82, 215, 255, 0.55);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.safe-area-shell {
  width: min(100%, 860px);
  margin-inline: auto;
  padding-inline: max(16px, env(safe-area-inset-left));
}

.login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 18px max(24px, env(safe-area-inset-bottom));
  background:
    linear-gradient(rgba(5, 11, 19, 0.86), rgba(5, 11, 19, 0.97)),
    repeating-linear-gradient(90deg, transparent 0 39px, rgba(82, 215, 255, 0.04) 40px),
    repeating-linear-gradient(0deg, transparent 0 39px, rgba(82, 215, 255, 0.04) 40px);
}

.login-card {
  width: min(100%, 400px);
  padding: 28px 22px 24px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(11, 21, 34, 0.96);
  box-shadow: var(--shadow);
}

.login-mark,
.brand-mark {
  display: grid;
  place-items: center;
  color: #03121b;
  background: linear-gradient(135deg, var(--cyan), var(--green));
  font-weight: 900;
  letter-spacing: -0.04em;
}

.login-mark {
  width: 54px;
  height: 54px;
  margin-bottom: 22px;
  border-radius: 16px;
  font-size: 20px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--cyan);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.login-card h1 {
  margin: 0;
  font-size: clamp(28px, 8vw, 38px);
  letter-spacing: -0.04em;
}

.login-card > p:not(.eyebrow) {
  margin: 12px 0 24px;
  color: var(--muted);
  line-height: 1.6;
}

.login-card form {
  display: grid;
  gap: 15px;
}

.login-card label {
  display: grid;
  gap: 7px;
}

.login-card label span {
  color: #b8c7d3;
  font-size: 13px;
  font-weight: 700;
}

.login-card input {
  width: 100%;
  min-height: 50px;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 0 14px;
  color: var(--text);
  background: #07111c;
}

.primary-button {
  min-height: 52px;
  border: 0;
  border-radius: 14px;
  color: #03151c;
  background: linear-gradient(120deg, var(--green), var(--cyan));
  font-weight: 850;
  cursor: pointer;
}

.primary-button:disabled {
  opacity: 0.6;
}

.form-error {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid rgba(255, 102, 124, 0.35);
  border-radius: 11px;
  color: #ffadba;
  background: rgba(255, 102, 124, 0.08);
  font-size: 13px;
}

.text-link {
  display: block;
  margin-top: 18px;
  color: var(--muted);
  text-align: center;
  text-decoration: none;
  font-size: 13px;
}

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  border-bottom: 1px solid rgba(82, 215, 255, 0.13);
  background: rgba(5, 11, 19, 0.9);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

.header-row {
  min-height: calc(66px + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 11px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 11px;
  font-size: 14px;
}

.brand-lockup p,
.brand-lockup h1 {
  margin: 0;
}

.brand-lockup p {
  color: var(--muted);
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.13em;
}

.brand-lockup h1 {
  font-size: 19px;
  letter-spacing: -0.025em;
}

.header-actions,
.sync-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: var(--surface);
  text-decoration: none;
  cursor: pointer;
  font-size: 19px;
}

.page-content {
  padding-top: 15px;
  padding-bottom: calc(36px + env(safe-area-inset-bottom));
}

.sync-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 24px;
  padding: 12px 13px;
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  background: rgba(12, 24, 37, 0.72);
}

.sync-state {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 9px;
}

.sync-state div {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.sync-state strong {
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sync-state small {
  color: var(--muted);
  font-size: 10px;
}

.sync-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 0 0 0 5px rgba(255, 202, 92, 0.1);
}

.sync-dot.online {
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(56, 227, 156, 0.1);
}

.sync-dot.error {
  background: var(--red);
  box-shadow: 0 0 0 5px rgba(255, 102, 124, 0.1);
}

.mini-button {
  min-height: 36px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: #b9c9d5;
  background: #0c1927;
  font-size: 11px;
  font-weight: 750;
  cursor: pointer;
}

.mini-button.is-active {
  border-color: rgba(56, 227, 156, 0.4);
  color: var(--green);
  background: rgba(56, 227, 156, 0.08);
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.compact-heading {
  margin-bottom: 11px;
}

.section-heading h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: -0.03em;
}

.database-badge {
  max-width: 48%;
  overflow: hidden;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9px;
  text-overflow: ellipsis;
}

.gateway-switcher {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.gateway-tab {
  min-width: 0;
  min-height: 86px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 15px;
  color: var(--text);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}

.gateway-tab.is-active {
  border-color: rgba(82, 215, 255, 0.65);
  background: linear-gradient(145deg, rgba(82, 215, 255, 0.12), rgba(20, 38, 57, 0.92));
  box-shadow: inset 0 0 0 1px rgba(82, 215, 255, 0.08);
}

.gateway-tab > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 5px;
}

.gateway-tab small {
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.gateway-tab b {
  display: block;
  overflow: hidden;
  margin: 8px 0 4px;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gateway-tab code {
  display: block;
  overflow: hidden;
  color: var(--dim);
  font-size: 9px;
  text-overflow: ellipsis;
}

.tab-state {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dim);
}

.tab-state.online { background: var(--green); box-shadow: 0 0 8px rgba(56, 227, 156, 0.8); }
.tab-state.stale { background: var(--yellow); }
.tab-state.offline { background: var(--red); }

.gateway-hero {
  position: relative;
  overflow: hidden;
  margin-bottom: 12px;
  padding: 19px 16px 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(145deg, #112436, #0b1522 58%);
  box-shadow: var(--shadow);
}

.gateway-hero::after {
  position: absolute;
  top: -80px;
  right: -75px;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: var(--state-glow, rgba(92, 113, 131, 0.12));
  filter: blur(10px);
  content: "";
}

.gateway-hero.state-online { --state-glow: rgba(56, 227, 156, 0.2); border-color: rgba(56, 227, 156, 0.28); }
.gateway-hero.state-stale { --state-glow: rgba(255, 202, 92, 0.2); border-color: rgba(255, 202, 92, 0.3); }
.gateway-hero.state-offline { --state-glow: rgba(255, 102, 124, 0.17); border-color: rgba(255, 102, 124, 0.28); }

.hero-topline {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.hero-topline h2 {
  margin: 0 0 4px;
  font-size: 24px;
  letter-spacing: -0.04em;
}

.hero-topline code {
  color: var(--muted);
  font-size: 11px;
}

.large-status {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 7px;
  min-height: 31px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(5, 11, 19, 0.6);
  font-size: 11px;
  font-weight: 850;
}

.large-status i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.state-online .large-status { color: var(--green); border-color: rgba(56, 227, 156, 0.28); }
.state-stale .large-status { color: var(--yellow); border-color: rgba(255, 202, 92, 0.3); }
.state-offline .large-status { color: var(--red); border-color: rgba(255, 102, 124, 0.28); }

.hero-detail {
  position: relative;
  z-index: 1;
  margin: 14px 0;
  color: #b3c4d1;
  font-size: 12px;
  line-height: 1.5;
}

.hero-metrics {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1.35fr 1fr 1fr;
  gap: 6px;
}

.hero-metrics div {
  min-width: 0;
  padding: 9px 8px;
  border: 1px solid var(--line-soft);
  border-radius: 11px;
  background: rgba(4, 12, 20, 0.44);
}

.hero-metrics span,
.hero-metrics strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hero-metrics span {
  margin-bottom: 4px;
  color: var(--dim);
  font-size: 8px;
  font-weight: 750;
  text-transform: uppercase;
}

.hero-metrics strong {
  font-size: 10px;
}

.diagnostic-alert {
  margin-bottom: 12px;
  padding: 13px 14px;
  border: 1px solid rgba(255, 202, 92, 0.34);
  border-radius: 14px;
  color: #ffe2a3;
  background: rgba(255, 202, 92, 0.08);
  font-size: 12px;
  line-height: 1.55;
}

.diagnostic-alert.error {
  border-color: rgba(255, 102, 124, 0.36);
  color: #ffb3bf;
  background: rgba(255, 102, 124, 0.08);
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.health-tile {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 8px;
  padding: 10px 8px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
}

.health-icon {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 9px;
  color: var(--muted);
  background: var(--surface-3);
  font-size: 9px;
  font-weight: 900;
}

.health-tile small,
.health-tile strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.health-tile small { color: var(--muted); font-size: 8px; }
.health-tile strong { margin-top: 3px; font-size: 10px; }
.health-tile.ok { border-color: rgba(56, 227, 156, 0.25); }
.health-tile.ok .health-icon, .health-tile.ok strong { color: var(--green); }
.health-tile.fail { border-color: rgba(255, 102, 124, 0.3); }
.health-tile.fail .health-icon, .health-tile.fail strong { color: var(--red); }

.debug-section {
  margin-bottom: 10px;
  overflow: clip;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(11, 21, 34, 0.9);
}

.debug-section > summary {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 13px;
  list-style: none;
  cursor: pointer;
}

.debug-section > summary::-webkit-details-marker { display: none; }

.debug-section > summary > span {
  display: grid;
  grid-template-columns: 34px 1fr;
  min-width: 0;
  align-items: center;
  column-gap: 10px;
}

.debug-section summary i {
  width: 34px;
  height: 34px;
  grid-row: 1 / span 2;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--cyan);
  background: rgba(82, 215, 255, 0.06);
  font-style: normal;
  font-size: 9px;
  font-weight: 900;
}

.debug-section summary b { font-size: 13px; }
.debug-section summary small { margin-top: 2px; color: var(--muted); font-size: 9px; }
.debug-section summary em { color: var(--muted); font-style: normal; transition: transform 160ms ease; }
.debug-section[open] summary em { transform: rotate(180deg); }
.debug-section[open] > summary { border-bottom: 1px solid var(--line-soft); }

.section-body {
  padding-top: 13px;
}

.data-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  background: var(--line-soft);
}

.data-item {
  min-width: 0;
  min-height: 63px;
  padding: 11px 13px;
  background: var(--surface);
}

.data-item span,
.data-item strong,
.data-item code {
  display: block;
  overflow-wrap: anywhere;
}

.data-item span {
  margin-bottom: 5px;
  color: var(--dim);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
}

.data-item strong,
.data-item code {
  color: #dce8ef;
  font-size: 11px;
}

.data-item code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.signal-card {
  margin: 0 13px 13px;
  padding: 14px;
  border: 1px solid var(--line-soft);
  border-radius: 13px;
  background: #09131f;
}

.signal-copy {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 3px 10px;
}

.signal-copy span { color: var(--muted); font-size: 10px; }
.signal-copy strong { grid-row: 1 / span 2; grid-column: 2; font-size: 20px; }
.signal-copy small { color: var(--cyan); font-size: 10px; }

.signal-track {
  height: 7px;
  overflow: hidden;
  margin-top: 12px;
  border-radius: 99px;
  background: #172a3a;
}

.signal-track i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--red), var(--yellow) 48%, var(--green));
  transition: width 300ms ease;
}

.inline-result,
.protocol-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 11px 13px;
  color: var(--muted);
  font-size: 10px;
}

.inline-result:empty,
.protocol-meta:empty { display: none; }

.meta-chip {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #09131f;
}

.meta-chip.ok { color: var(--green); border-color: rgba(56, 227, 156, 0.3); }
.meta-chip.fail { color: var(--red); border-color: rgba(255, 102, 124, 0.32); }

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

.analog-card {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  background: #09131f;
}

.analog-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--cyan);
  font-size: 10px;
  font-weight: 850;
}

.analog-card header span:last-child { color: var(--dim); font-size: 8px; }
.analog-card strong { display: block; margin-top: 8px; font-size: 20px; letter-spacing: -0.04em; }
.analog-card small { display: block; margin-top: 3px; color: var(--muted); font-size: 9px; }

.empty-state {
  grid-column: 1 / -1;
  padding: 18px;
  color: var(--muted);
  text-align: center;
  font-size: 11px;
}

.io-block {
  padding: 13px;
}

.io-block + .io-block {
  border-top: 1px solid var(--line-soft);
}

.subsection-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 11px;
}

.subsection-title span {
  color: var(--muted);
  font-size: 9px;
}

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

.digital-bit {
  min-height: 50px;
  display: grid;
  place-items: center;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  background: #08121e;
  font-size: 9px;
  font-weight: 800;
}

.digital-bit::before {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #364d60;
  content: "";
}

.digital-bit.on {
  border-color: rgba(56, 227, 156, 0.35);
  color: var(--green);
  background: rgba(56, 227, 156, 0.07);
}

.digital-bit.on::before { background: var(--green); box-shadow: 0 0 9px rgba(56, 227, 156, 0.9); }
.output-grid .digital-bit.on { border-color: rgba(82, 215, 255, 0.36); color: var(--cyan); background: rgba(82, 215, 255, 0.07); }
.output-grid .digital-bit.on::before { background: var(--cyan); box-shadow: 0 0 9px rgba(82, 215, 255, 0.9); }

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.technical-table {
  width: 100%;
  border-collapse: collapse;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
}

.technical-table th,
.technical-table td {
  padding: 10px 13px;
  border-top: 1px solid var(--line-soft);
  text-align: left;
  white-space: nowrap;
}

.technical-table th { color: var(--dim); font-size: 8px; text-transform: uppercase; }
.technical-table td { color: #c9d7e1; }

.message-timeline {
  padding: 5px 13px 13px;
}

.message-row {
  position: relative;
  display: grid;
  grid-template-columns: 9px minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line-soft);
}

.message-row:last-child { border-bottom: 0; }
.message-row > i { width: 8px; height: 8px; margin-top: 5px; border-radius: 50%; background: var(--blue); }
.message-row.telemetry > i { background: var(--cyan); }
.message-row.heartbeat > i { background: var(--green); }
.message-row.status > i { background: var(--yellow); }
.message-row.event > i { background: #b38cff; }
.message-copy { min-width: 0; }
.message-copy strong, .message-copy code { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-copy strong { font-size: 11px; }
.message-copy code { margin-top: 3px; color: var(--dim); font-size: 8px; }
.message-row time { color: var(--muted); font-size: 9px; }

.raw-toolbar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 12px 13px 8px;
}

.raw-tab {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--muted);
  background: #08121e;
  font-size: 10px;
  cursor: pointer;
}

.raw-tab.is-active { border-color: rgba(82, 215, 255, 0.4); color: var(--cyan); background: rgba(82, 215, 255, 0.07); }

.raw-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 13px 9px;
}

.raw-actions span { color: var(--dim); font-size: 9px; }

.raw-section pre {
  max-height: 520px;
  overflow: auto;
  margin: 0;
  padding: 14px;
  border-top: 1px solid var(--line-soft);
  color: #b9eaff;
  background: #040a11;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.page-footer {
  padding: 17px 2px 0;
  color: var(--dim);
  text-align: center;
  font-size: 9px;
}

.page-footer p { margin: 0 0 9px; }
.page-footer div { display: flex; justify-content: center; gap: 12px; }

.toast {
  position: fixed;
  z-index: 50;
  right: 16px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  left: 16px;
  width: min(calc(100% - 32px), 420px);
  margin-inline: auto;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--text);
  background: #102033;
  box-shadow: var(--shadow);
  text-align: center;
  font-size: 12px;
}

@media (min-width: 600px) {
  .page-content { padding-top: 20px; }
  .gateway-tab { min-height: 95px; }
  .hero-metrics span { font-size: 9px; }
  .hero-metrics strong { font-size: 12px; }
  .data-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .analog-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .digital-grid { grid-template-columns: repeat(8, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
