:root {
  color-scheme: light;
  --page: #f3f6fa;
  --surface: #ffffff;
  --surface-muted: #f7f9fc;
  --line: #d8e0ec;
  --line-strong: #c7d2e2;
  --text: #172131;
  --muted: #64738a;
  --blue: #2764d9;
  --blue-dark: #1f52b6;
  --blue-soft: #edf4ff;
  --green: #138a64;
  --green-soft: #eaf8f3;
  --red: #c83c35;
  --red-soft: #fff1f0;
  --amber: #a96608;
  --amber-soft: #fff7e8;
  --shadow: 0 12px 32px rgba(31, 55, 88, 0.12);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background: var(--page);
  color: var(--text);
}

button,
input,
select,
textarea {
  color: inherit;
  font: inherit;
  letter-spacing: 0;
}

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

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid rgba(39, 100, 217, 0.35);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.shell {
  width: min(1500px, calc(100% - 40px));
  margin: 0 auto;
  padding: 26px 0 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 54px;
  margin-bottom: 16px;
}

.titleBlock h1,
.loginPanel h1,
.modalHeader h2,
.sectionHeader h2 {
  margin: 0;
  letter-spacing: 0;
}

.titleBlock h1 {
  font-size: 28px;
  line-height: 1.25;
}

.titleBlock p,
.modalHeader p,
.loginPanel p {
  margin: 4px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.topActions,
.controllerActions,
.editActions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.primaryButton,
.secondaryButton,
.dangerButton,
.iconButton,
.rowButton {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

/* 不可连的连接按钮：视觉弱化但仍可点，点了会给出不能连的具体原因。 */
.rowButton.muted {
  color: var(--muted);
  border-color: var(--line);
}

/* 配置控制端弹窗的说明文字。 */
.controllerHint {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.primaryButton {
  border-color: var(--blue);
  background: var(--blue);
  color: #ffffff;
}

.primaryButton:hover {
  background: var(--blue-dark);
}

.secondaryButton,
.rowButton {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--blue);
}

.dangerButton {
  border-color: #efb4b0;
  background: var(--red-soft);
  color: var(--red);
}

.iconButton {
  width: 38px;
  padding: 0;
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--blue);
  font-size: 20px;
}

.navButton {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  overflow: hidden;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.summary div {
  min-width: 0;
  padding: 16px 18px;
  border-right: 1px solid var(--line);
}

.summary div:last-child {
  border-right: 0;
}

.summary strong,
.summary span {
  display: block;
}

.summary strong {
  font-size: 25px;
  line-height: 1.15;
}

.summary span {
  margin-top: 4px;
  color: var(--muted);
}

.settingsBar,
.toolbar,
.deviceSection {
  border: 1px solid var(--line);
  background: var(--surface);
}

.settingsBar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
  border-radius: 8px;
  padding: 11px 14px;
}

.settingsBar > div {
  display: flex;
  align-items: center;
  gap: 10px;
}

.settingsBar > div span {
  color: var(--muted);
}

.switchControl {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  cursor: pointer;
}

.switchControl input {
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: var(--blue);
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) 180px 180px;
  gap: 12px;
  margin-bottom: 12px;
  border-radius: 8px;
  padding: 12px;
}

.toolbar label,
.modalBody > label,
.loginPanel label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.toolbar label > span,
.modalBody > label > span,
.loginPanel label > span,
.platformOptions legend {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
}

input,
select {
  height: 38px;
  padding: 0 11px;
}

textarea {
  resize: vertical;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
}

.deviceSection {
  overflow: hidden;
  border-radius: 8px;
}

.sectionHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 46px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
}

.sectionHeader h2 {
  font-size: 16px;
}

.sectionHeader span {
  color: var(--muted);
}

.tableWrap {
  overflow-x: auto;
}

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

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

th {
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

th:nth-child(1) { width: 25%; }
th:nth-child(2) { width: 12%; }
th:nth-child(3) { width: 10%; }
th:nth-child(4) { width: 12%; }
th:nth-child(5) { width: 12%; }
th:nth-child(6) { width: 14%; }
th:nth-child(7) { width: 15%; }

tbody tr:last-child td {
  border-bottom: 0;
}

.deviceIdentity {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.deviceName {
  overflow: hidden;
  color: var(--text);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.deviceMeta,
.cellSecondary {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.statusBadge,
.platformBadge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.statusBadge::before {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #98a5b8;
  content: "";
}

.statusBadge.online {
  border-color: #b7dfd1;
  background: var(--green-soft);
  color: var(--green);
}

.statusBadge.online::before {
  background: var(--green);
}

.statusBadge.offline {
  background: var(--surface-muted);
  color: var(--muted);
}

.statusBadge.disabled {
  border-color: #e7c8a0;
  background: var(--amber-soft);
  color: var(--amber);
}

.statusBadge.disabled::before {
  background: var(--amber);
}

.platformBadge {
  border-color: #c8d8f4;
  background: var(--blue-soft);
  color: #315f9f;
}

.rowActions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.rowButton {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.empty {
  height: 150px;
  color: var(--muted);
  text-align: center;
}

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

.loginPanel {
  display: grid;
  gap: 14px;
  width: min(400px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 24px;
  box-shadow: var(--shadow);
}

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

.message {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.message.error {
  color: var(--red);
}

.modalBackdrop {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  overflow-y: auto;
  place-items: center;
  padding: 24px;
  background: rgba(23, 33, 49, 0.42);
}

.modal {
  width: min(680px, 100%);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.compactModal {
  width: min(480px, 100%);
}

.modalHeader {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.modalHeader h2 {
  font-size: 19px;
}

.modalBody {
  display: grid;
  gap: 14px;
  padding: 18px 20px 20px;
}

.closeButton {
  flex: 0 0 auto;
  width: 34px;
  min-height: 34px;
}

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

.platformOptions legend {
  grid-column: 1 / -1;
  margin-bottom: 6px;
}

.platformOptions label {
  position: relative;
}

.platformOptions input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.platformOptions span {
  display: grid;
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  place-items: center;
  font-weight: 600;
  cursor: pointer;
}

.platformOptions input:checked + span {
  border-color: var(--blue);
  background: var(--blue-soft);
  color: var(--blue);
}

.generateButton {
  justify-self: start;
}

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

.commandHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.controllerActions .primaryButton,
.controllerActions .secondaryButton {
  flex: 1;
}

.editSwitch {
  justify-self: start;
}

.editActions {
  justify-content: space-between;
}

@media (max-width: 900px) {
  .shell {
    width: min(100% - 24px, 760px);
    padding-top: 18px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topActions {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .summary div:nth-child(2) {
    border-right: 0;
  }

  .summary div:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }

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

  .searchControl {
    grid-column: 1 / -1;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  tbody {
    display: grid;
    gap: 8px;
    padding: 8px;
  }

  tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 12px;
  }

  tbody td {
    min-width: 0;
    border: 0;
    padding: 0;
  }

  tbody td:nth-child(1),
  tbody td:nth-child(5),
  tbody td:nth-child(6) {
    grid-column: 1;
  }

  tbody td:nth-child(2),
  tbody td:nth-child(3),
  tbody td:nth-child(4) {
    grid-column: 2;
    justify-self: end;
  }

  tbody td:nth-child(2) {
    grid-row: 1;
  }

  tbody td:nth-child(3) {
    grid-row: 2;
  }

  tbody td:nth-child(4) {
    grid-row: 3;
  }

  tbody td:nth-child(5) {
    grid-row: 2;
  }

  tbody td:nth-child(6) {
    grid-row: 3;
  }

  tbody td:nth-child(7) {
    grid-column: 1 / -1;
    grid-row: 4;
    padding-top: 10px;
    border-top: 1px solid var(--line);
  }

  tbody td:nth-child(3)::before,
  tbody td:nth-child(4)::before,
  tbody td:nth-child(5)::before,
  tbody td:nth-child(6)::before {
    display: block;
    margin-bottom: 3px;
    color: var(--muted);
    content: attr(data-label);
    font-size: 11px;
    font-weight: 600;
  }

  .rowActions {
    justify-content: flex-end;
  }

  .empty {
    display: grid;
    grid-column: 1 / -1 !important;
    min-height: 120px;
    place-items: center;
  }
}

@media (max-width: 520px) {
  :root {
    font-size: 13px;
  }

  .shell {
    width: calc(100% - 16px);
    padding-top: 12px;
  }

  .titleBlock h1 {
    font-size: 23px;
  }

  .topActions .navButton {
    display: none;
  }

  .summary div {
    padding: 13px 14px;
  }

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

  .settingsBar {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .searchControl {
    grid-column: auto;
  }

  .modalBackdrop {
    align-items: end;
    padding: 8px;
  }

  .modal {
    max-height: calc(100vh - 16px);
    overflow-y: auto;
  }

  .modalHeader,
  .modalBody {
    padding-right: 14px;
    padding-left: 14px;
  }

  .rowActions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .rowButton {
    width: 100%;
  }

  .controllerActions {
    align-items: stretch;
    flex-direction: column;
  }
}
