:root {
  --bg: #eef4f8;
  --ink: #07131f;
  --muted: #4f6378;
  --navy: #081624;
  --navy-2: #0e2d43;
  --blue: #19a2c9;
  --blue-2: #0474ad;
  --green: #38d49a;
  --red: #e64b55;
  --amber: #f2b84b;
  --line: #d4e3ee;
  --panel: #fff;
  --shadow: 0 18px 44px rgba(8, 22, 36, .12);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--ink);
  letter-spacing: 0;
}

button, input, select { font: inherit; }
button { cursor: pointer; border: 0; font-weight: 900; }
h1, h2, p { margin: 0; }

.app {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 0 calc(92px + env(safe-area-inset-bottom));
}

.splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  color: #fff;
  background: linear-gradient(160deg, #041421, #073c5e 58%, #0a8eba);
  transition: opacity .35s ease, visibility .35s ease;
}
.splash.hide { opacity: 0; visibility: hidden; }
.splash strong { font-size: 46px; line-height: 1; }
.splash span { font-size: 34px; font-weight: 900; color: #ddf0f9; }
.splash p { color: #d0e7f5; }
.splash-orbit {
  width: 145px;
  height: 145px;
  position: relative;
  border-radius: 50%;
  background: radial-gradient(circle, #20a8d0 0 34%, #0d2538 35% 58%, transparent 59%);
  box-shadow: 0 0 0 28px rgba(38, 214, 243, .12), 0 0 0 56px rgba(36, 214, 154, .08);
  animation: breathe 1.4s ease-in-out infinite alternate;
}
.splash-orbit i {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  left: 34px;
  top: 42px;
}
.splash-orbit i:nth-child(2) { background: var(--green); left: 90px; top: 82px; }
.splash-orbit i:nth-child(3) { background: var(--blue); left: 72px; top: 22px; }
@keyframes breathe { from { transform: scale(.92); } to { transform: scale(1.08); } }

.scan-screen {
  min-height: calc(100vh - 32px);
  display: grid;
  place-items: center;
}
.scan-card {
  width: min(620px, 100%);
  display: grid;
  justify-items: center;
  gap: 20px;
  padding: 48px 38px;
  border-radius: 34px;
  color: #fff;
  text-align: center;
  background: linear-gradient(145deg, #057abc, #081624);
  box-shadow: var(--shadow);
}
.scan-card img {
  width: 78px;
  height: 78px;
  padding: 10px;
  border-radius: 18px;
  background: #07131f;
}
.scan-card h1 { font-size: clamp(34px, 6vw, 52px); }
.scan-card p { max-width: 500px; color: #e2f3fb; font-size: 20px; line-height: 1.38; }
.role-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
}
.role-btn, .secondary-action, .primary-action, .disconnect-button, .danger-action {
  min-height: 58px;
  border-radius: 18px;
  padding: 12px 18px;
}
.role-btn {
  color: #fff;
  background: #102a3e;
  border: 1px solid rgba(255,255,255,.24);
}
.role-btn.active {
  color: #07131f;
  background: #fff;
  box-shadow: 0 10px 26px rgba(0,0,0,.18);
}
.scan-pulse {
  width: 218px;
  height: 218px;
  border-radius: 50%;
  color: #fff;
  font-size: 28px;
  background: var(--blue);
  box-shadow: 0 18px 30px rgba(0,0,0,.25), 0 0 0 0 rgba(25,162,201,.38);
  animation: scanPulse 1.7s ease-out infinite;
}
@keyframes scanPulse {
  70% { box-shadow: 0 18px 30px rgba(0,0,0,.25), 0 0 0 34px rgba(25,162,201,0); }
  100% { box-shadow: 0 18px 30px rgba(0,0,0,.25), 0 0 0 0 rgba(25,162,201,0); }
}

.app-screen { display: grid; gap: 18px; }
.top-card, .dark-panel {
  color: #fff;
  background: var(--navy);
  border: 1px solid #03101b;
  border-radius: 30px;
  box-shadow: var(--shadow);
}
.top-card {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 20px;
}
.menu-button {
  width: 64px;
  height: 64px;
  display: grid;
  align-content: center;
  gap: 7px;
  padding: 0 17px;
  border-radius: 16px;
  background: #102a3e;
}
.menu-button span {
  height: 4px;
  border-radius: 999px;
  background: #fff;
}
.top-card img {
  width: 58px;
  height: 58px;
  padding: 7px;
  border-radius: 14px;
  background: #102a3e;
}
.title-block h1 { font-size: clamp(28px, 4vw, 40px); }
.title-block p { color: #c7d9e6; font-size: 20px; }
.disconnect-button {
  color: #fff;
  background: var(--blue);
  min-width: 180px;
  box-shadow: 0 12px 26px rgba(25,162,201,.28);
}

.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(360px, .9fr);
  gap: 18px;
}
.module-panel {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 28px;
  align-items: center;
  padding: 28px;
}
#moduleCanvas {
  width: 178px;
  height: 150px;
}
.module-panel h2 {
  margin-top: 6px;
  color: var(--green);
  font-size: clamp(32px, 5vw, 48px);
  line-height: 1.08;
}
.module-panel p { color: #ddf0f9; font-size: 22px; }

.white-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 30px;
  box-shadow: var(--shadow);
}
.diagnostics {
  padding: 28px;
}
.diagnostics h2, .settings-panel h2 { font-size: 32px; }
.diagnostics > p, .settings-panel p { color: var(--muted); margin-top: 8px; font-size: 20px; }
.diag-rows {
  display: grid;
  gap: 18px;
  margin-top: 28px;
}
.diag-rows div {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  font-size: 22px;
}
.diag-rows span { color: #37516a; }
.diag-rows strong { text-align: right; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.metric-grid > div {
  min-height: 96px;
  padding: 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
}
.metric-grid span { display: block; color: var(--muted); margin-bottom: 10px; }
.metric-grid strong { font-size: 26px; overflow-wrap: anywhere; }

.settings-panel { padding: 26px; }
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: start;
  margin-bottom: 24px;
}
.primary-action {
  color: #fff;
  background: var(--blue);
  box-shadow: 0 12px 26px rgba(25,162,201,.28);
}
.secondary-action {
  color: var(--ink);
  background: #eaf4fa;
  border: 1px solid var(--line);
}
.danger-action { color: #fff; background: var(--red); }
.primary-action:disabled, .secondary-action:disabled {
  opacity: .55;
  cursor: wait;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }
.field-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}
label {
  display: grid;
  gap: 8px;
  color: #536579;
  font-weight: 900;
}
select, input {
  width: 100%;
  min-height: 58px;
  padding: 12px 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: #f7fbfe;
  color: var(--ink);
  font-weight: 900;
}
select:focus, input:focus {
  outline: 4px solid rgba(25,162,201,.15);
  border-color: var(--blue);
}
select.manual-on {
  border-color: rgba(56,212,154,.65);
  background: #eafff6;
  color: #07583b;
}

.io-list {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}
.io-row {
  display: grid;
  grid-template-columns: 130px 1.25fr repeat(5, minmax(0, 1fr));
  gap: 12px;
  padding: 14px;
  border-radius: 20px;
  background: #f4f9fc;
  border: 1px solid var(--line);
  align-items: center;
}
.io-pin {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 900;
}
.io-pin span {
  color: var(--muted);
  font-size: 14px;
}
.io-link {
  display: grid;
  gap: 6px;
  min-height: 58px;
  padding: 10px 14px;
  border-radius: 16px;
  background: #eaf6fb;
  border: 1px solid #cce3ef;
}
.io-link span {
  color: var(--muted);
  font-weight: 900;
  font-size: 13px;
}
.io-link strong {
  color: var(--ink);
  overflow-wrap: anywhere;
}
.dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--red);
}
.dot.active { background: var(--green); }
.dot.disabled { background: #70869a; }

.service-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.scanner-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: center;
  padding: 18px;
  border-radius: 24px;
  color: #fff;
  background: #081624;
}
.scanner-card h3 {
  margin: 10px 0 6px;
  font-size: 30px;
}
.scanner-card p { color: #bfd3e0; }
.scanner-badge {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  color: #081624;
  background: #eaf4fa;
  font-weight: 900;
}
.scanner-badge.active {
  color: #052015;
  background: #38d49a;
}
.scanner-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 10px;
}
.scanner-grid { margin-top: 16px; }
.scanner-payload {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding: 18px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: #f4f9fc;
}
.scanner-payload span { color: var(--muted); font-weight: 900; }
.scanner-payload strong {
  font-family: Consolas, Monaco, monospace;
  overflow-wrap: anywhere;
}
.ota-line { margin-top: 18px; }
progress { width: 100%; height: 18px; margin: 14px 0; }
pre {
  min-height: 320px;
  max-height: 520px;
  overflow: auto;
  padding: 18px;
  margin: 0;
  border-radius: 18px;
  color: #ddf0f9;
  background: #07131f;
  white-space: pre-wrap;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 30;
  width: min(720px, calc(100% - 22px));
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  padding: 10px;
  border-radius: 24px;
  background: rgba(255,255,255,.94);
  box-shadow: 0 10px 34px rgba(8,22,36,.16);
}
.nav-btn {
  min-height: 58px;
  border-radius: 18px;
  color: var(--ink);
  background: transparent;
}
.nav-btn.active { background: #e9d8ff; }

.drawer-backdrop, .dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(5,14,24,.46);
}
.side-menu {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 51;
  width: min(390px, calc(100vw - 34px));
  padding: 18px;
  background: #fff;
  transform: translateX(-106%);
  transition: transform .22s ease;
  box-shadow: 24px 0 46px rgba(8,22,36,.24);
}
.side-menu.open { transform: translateX(0); }
.side-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.side-head strong { display: block; font-size: 26px; }
.side-head span { color: var(--muted); }
.side-head button, .side-menu > button {
  background: #eef5fa;
  color: var(--ink);
}
.side-menu > button {
  width: 100%;
  display: grid;
  gap: 4px;
  text-align: left;
  margin-bottom: 10px;
  padding: 16px;
  border-radius: 18px;
}
.side-menu > button.active {
  color: #fff;
  background: var(--navy);
}
.side-menu span { color: var(--muted); font-size: 14px; }
.side-menu button.active span { color: #bfd3e0; }

.dialog-backdrop {
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 20px;
}
.dialog-card {
  width: min(430px, 100%);
  display: grid;
  gap: 14px;
  padding: 26px;
  border-radius: 26px;
  background: #fff;
  box-shadow: var(--shadow);
}
.dialog-card strong { font-size: 28px; }
.dialog-card p { color: var(--muted); line-height: 1.45; }
.dialog-card button {
  min-height: 54px;
  border-radius: 18px;
  color: #fff;
  background: var(--blue);
}

[hidden] { display: none !important; }

@media (max-width: 900px) {
  .app { width: min(100% - 24px, 1180px); }
  .top-card { grid-template-columns: auto auto 1fr; }
  .disconnect-button { grid-column: 1 / -1; width: 100%; }
  .hero-grid, .module-panel { grid-template-columns: 1fr; }
  .module-panel { justify-items: center; text-align: center; }
  .field-grid, .metric-grid, .service-grid, .scanner-card, .scanner-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .io-row { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
  .app { width: min(100% - 20px, 1180px); }
  .scan-card { padding: 34px 22px; }
  .scan-card p { font-size: 18px; }
  .role-switch, .field-grid, .metric-grid, .service-grid, .scanner-card, .scanner-actions, .io-row { grid-template-columns: 1fr; }
  .panel-head { display: grid; }
  .top-card { gap: 12px; }
  .menu-button { width: 58px; height: 58px; }
  .top-card img { width: 52px; height: 52px; }
  .title-block h1 { font-size: 28px; }
  .title-block p { font-size: 18px; }
}
