* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --line: #d8e0e8;
  --line-strong: #b8c4d0;
  --text: #17202a;
  --muted: #5b6876;
  --brand: #1769aa;
  --brand-strong: #0f4f83;
  --ok: #137a45;
  --warn: #b7791f;
  --bad: #b42318;
}

body {
  margin: 0;
  font-family: "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
}

button:hover {
  background: var(--brand-strong);
}

button.secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--line-strong);
}

button.secondary:hover {
  background: #f6f8fb;
}

button.danger,
.icon-danger {
  border-color: #fecaca;
  background: #fff;
  color: var(--bad);
}

button.danger:hover,
.icon-danger:hover {
  border-color: #dc2626;
  background: #fef2f2;
}

input,
select {
  min-width: 0;
  width: 100%;
  border: 1px solid #c5d0dc;
  border-radius: 6px;
  padding: 8px;
  background: #fff;
}

h1,
h2,
h3,
p {
  margin: 0;
}

p {
  color: var(--muted);
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(100%, 420px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 18px 50px rgba(23, 32, 42, 0.08);
}

.login-card h1 {
  font-size: 24px;
}

.login-card p {
  margin-top: 8px;
}

.login-card label {
  display: grid;
  gap: 6px;
  margin: 16px 0;
}

.login-card button {
  width: 100%;
}

#login-msg {
  min-height: 20px;
  margin-top: 10px;
  color: var(--bad);
}

.admin-root {
  min-height: 100vh;
}

.moni-root {
  max-width: 1320px;
  margin: 0 auto;
  padding: 22px;
  display: grid;
  gap: 14px;
}

.moni-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.moni-topbar h1 {
  font-size: 26px;
}

.moni-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.text-link {
  color: var(--brand);
  font-weight: 700;
  text-decoration: none;
}

.text-link:hover {
  color: var(--brand-strong);
  text-decoration: underline;
}

.wall-view {
  max-width: 1440px;
  margin: 0 auto;
  padding: 22px;
}

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

.wall-topbar h1 {
  font-size: 26px;
}

.wall-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.detail-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
}

.detail-sidebar {
  background: #102a43;
  color: #d9e2ec;
  padding: 18px 14px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 20px;
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  position: sticky;
  top: 0;
}

.brand {
  display: grid;
  gap: 4px;
  padding: 4px 6px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.16);
}

.brand strong {
  font-size: 22px;
}

.brand span {
  color: #bcccdc;
  font-size: 13px;
}

.back-button {
  width: 100%;
  margin-bottom: 10px;
  border-color: rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.back-button:hover {
  background: rgba(255, 255, 255, 0.16);
}

.tabs {
  display: grid;
  align-content: start;
  gap: 6px;
  min-height: 0;
}

.tab {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: #d9e2ec;
  padding: 10px 12px;
}

.tab:hover,
.tab.active {
  background: #1f4e79;
}

.sidebar-actions {
  display: grid;
  gap: 8px;
}

.main {
  padding: 22px;
  min-width: 0;
}

.topbar,
.section-head,
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 18px;
}

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

.selected-device {
  min-width: 210px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 10px 12px;
  display: grid;
  gap: 4px;
}

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

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 14px;
}

.section-head {
  margin-bottom: 2px;
}

.section-head h2 {
  font-size: 20px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  min-width: 0;
}

.panel-head {
  margin-bottom: 14px;
}

.panel-head h3 {
  font-size: 17px;
}

.split {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 14px;
}

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}

.device-card {
  text-align: left;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  gap: 10px;
  cursor: pointer;
}

.device-card:hover,
.device-card.active {
  border-color: var(--brand);
  background: #f8fbff;
}

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

.card-head strong {
  font-size: 17px;
}

.card-id,
.card-foot {
  color: var(--muted);
  font-size: 13px;
}

.card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-top: 1px solid #e5ebf1;
  padding-top: 10px;
}

.card-actions span {
  color: var(--muted);
  font-size: 13px;
}

.card-actions button {
  padding: 6px 10px;
}

.card-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.card-metrics span {
  display: grid;
  gap: 2px;
  background: #f6f8fb;
  border: 1px solid #e5ebf1;
  border-radius: 6px;
  padding: 8px;
  color: var(--muted);
  font-size: 12px;
}

.card-metrics b {
  color: var(--text);
  font-size: 14px;
}

.badge {
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  border: 1px solid var(--line);
}

.badge.online {
  color: var(--ok);
  background: #ecfdf3;
  border-color: #bbf7d0;
}

.badge.warn {
  color: var(--warn);
  background: #fffbeb;
  border-color: #fde68a;
}

.badge.offline {
  color: var(--bad);
  background: #fef2f2;
  border-color: #fecaca;
}

.device-list {
  display: grid;
  gap: 8px;
}

.device-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #f8fafc;
}

.device-row.active {
  border-color: var(--brand);
  background: #edf7ff;
}

.device-row > button:first-child {
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 0;
  display: grid;
  gap: 4px;
}

.device-row span {
  color: var(--muted);
  font-size: 13px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.button-row,
.actions,
.ota-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.ota-row input {
  flex: 1 1 420px;
}

.ota-upload {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto minmax(180px, auto);
  gap: 10px;
  align-items: end;
  margin: 14px 0;
  padding: 12px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
}

.ota-upload span {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
  align-self: center;
}

.panel-subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 14px 0 10px;
}

.panel-subhead h3 {
  font-size: 15px;
}

.ota-packages {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.ota-package {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.ota-package > div:first-child {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.ota-package span,
.ota-package code {
  color: var(--muted);
  font-size: 13px;
}

.ota-package strong,
.ota-package code {
  overflow-wrap: anywhere;
}

.ota-package-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.ota-package-actions button {
  padding: 7px 10px;
}

code {
  font-family: Consolas, "Courier New", monospace;
}

.modem-links,
.sim-modem-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.modem-link,
.simulation-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.modem-link {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 12px;
  padding: 12px;
  border-left: 4px solid var(--line-strong);
}

.modem-link.working {
  border-left-color: var(--ok);
  background: #f6fff9;
}

.modem-link.disconnected {
  border-left-color: var(--bad);
  background: #fffafa;
}

.modem-link strong,
.modem-link span,
.modem-link b,
.modem-link p {
  overflow-wrap: anywhere;
}

.modem-link span,
.modem-link p {
  color: var(--muted);
  font-size: 13px;
}

.modem-link p {
  grid-column: 1 / -1;
  margin: 0;
}

.modem-link b {
  align-self: start;
  color: var(--text);
  font-size: 14px;
}

.simulation-panel {
  display: grid;
  gap: 14px;
}

.simulation-toolbar,
.sim-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.simulation-toolbar {
  justify-content: space-between;
  padding: 12px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
}

.simulation-toolbar span {
  color: var(--muted);
  font-size: 13px;
}

.check-row {
  width: fit-content;
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.check-row input {
  width: auto;
  min-width: 0;
}

.simulation-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  gap: 14px;
}

.simulation-card {
  padding: 14px;
  min-width: 0;
}

.simulation-card-wide {
  min-height: 260px;
}

.sim-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: #f8fafc;
  color: var(--muted);
  padding: 0 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.sim-badge.ok {
  border-color: #bbf7d0;
  background: #ecfdf3;
  color: var(--ok);
}

.sim-badge.warn {
  border-color: #fde68a;
  background: #fffbeb;
  color: var(--warn);
}

.sim-badge.bad {
  border-color: #fecaca;
  background: #fef2f2;
  color: var(--bad);
}

.sim-serial-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.sim-port {
  min-height: 34px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 13px;
}

.sim-port.online {
  border-color: #bbf7d0;
  background: #ecfdf3;
  color: var(--ok);
}

.sim-port.offline,
.port.sim-offline {
  border-color: #fecaca;
  background: #fff7f7;
}

.sim-port.offline {
  color: var(--bad);
}

.serial-transmit-panel {
  display: grid;
  gap: 12px;
}

.serial-transmit-form {
  display: grid;
  grid-template-columns: 140px minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.serial-data-card {
  width: min(920px, calc(100vw - 28px));
}

.serial-data-output {
  min-height: 220px;
  max-height: 58vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.port.sim-offline .port-main strong,
.port.sim-offline .port-main span {
  color: var(--bad);
}

.kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
}

.kv-grid div,
.metric-grid div {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 6px;
  background: #fbfdff;
}

.kv-grid strong,
.metric-grid span {
  color: var(--muted);
  font-size: 13px;
}

.kv-grid span {
  font-size: 15px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

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

.metric-grid strong {
  font-size: 24px;
}

.table {
  margin-top: 12px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 560px;
}

th,
td {
  border-bottom: 1px solid #e2e8f0;
  padding: 10px;
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 13px;
  background: #f8fafc;
}

.ports {
  display: grid;
  gap: 10px;
}

.port {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 130px 130px 120px 120px 72px;
  gap: 8px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.port-main {
  display: grid;
  gap: 4px;
  align-self: center;
}

.port-main span,
.port-detail {
  color: var(--muted);
  font-size: 13px;
}

.port-detail {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding-top: 4px;
}

.commands {
  display: grid;
  gap: 8px;
}

.command {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.command summary {
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.command-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  margin: 10px 0;
}

pre {
  white-space: pre-wrap;
  overflow: auto;
  background: #102a43;
  color: #e6edf3;
  border-radius: 8px;
  padding: 12px;
  max-height: 520px;
}

.log-box {
  margin-top: 12px;
  min-height: 160px;
}

.drawer {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  display: grid;
  place-items: center;
  padding: 20px;
}

.drawer-card {
  width: min(100%, 520px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.18);
}

.drawer-card label {
  margin-bottom: 12px;
}

.empty {
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  padding: 18px;
  color: var(--muted);
  background: #fff;
}

@media (max-width: 1040px) {
  .detail-shell {
    grid-template-columns: 1fr;
  }

  .detail-sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    grid-template-rows: auto auto;
    gap: 12px;
    height: auto;
    max-height: 55vh;
  }

  .tabs {
    display: flex;
    overflow: auto;
  }

  .tab {
    white-space: nowrap;
  }

  .sidebar-actions {
    grid-template-columns: 1fr 1fr;
  }

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

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

  .ota-upload,
  .ota-package,
  .simulation-grid {
    grid-template-columns: 1fr;
  }

  .ota-package-actions {
    justify-content: flex-start;
  }

  .simulation-toolbar {
    justify-content: flex-start;
  }

  .serial-transmit-form {
    grid-template-columns: 1fr;
  }

  .port-main,
  .port-detail {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  .main {
    padding: 14px;
  }

  .wall-view {
    padding: 14px;
  }

  .wall-topbar {
    display: grid;
  }

  .moni-root {
    padding: 14px;
  }

  .moni-topbar {
    display: grid;
  }

  .topbar,
  .section-head,
  .panel-head,
  .form-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .selected-device {
    width: 100%;
  }

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