:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #d7dee8;
  --line-soft: #e8edf3;
  --text: #141922;
  --muted: #667085;
  --rail: #111827;
  --rail-soft: #1f2937;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --ok: #059669;
  --warn: #d97706;
  --error: #dc2626;
  --code: #0b1220;
  --shadow: 0 12px 28px rgb(15 23 42 / 8%);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

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

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px;
  background: var(--rail);
  color: #e5e7eb;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 18px;
  border-bottom: 1px solid rgb(255 255 255 / 10%);
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: #e5f0ff;
  color: #174ea6;
  font-weight: 800;
}

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

.brand span {
  margin-top: 3px;
  color: #9ca3af;
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 6px;
  margin-top: 18px;
}

.nav-list a {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 6px;
  color: #cbd5e1;
  font-size: 14px;
  text-decoration: none;
}

.nav-list a:hover,
.nav-list a.active {
  background: var(--rail-soft);
  color: #ffffff;
}

.sidebar-footer {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid rgb(255 255 255 / 10%);
  border-radius: 8px;
  background: rgb(255 255 255 / 4%);
}

.sidebar-footer span {
  color: #9ca3af;
  font-size: 12px;
}

.workspace {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  background: rgb(255 255 255 / 94%);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
}

h2 {
  font-size: 16px;
  line-height: 1.35;
}

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

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(340px, 0.75fr);
  gap: 16px;
  padding: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 0;
  margin-bottom: 14px;
}

.status-panel,
.command-panel,
.table-panel {
  grid-column: 1;
}

.device-panel,
.messages-panel {
  grid-column: 2;
}

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

.status-grid,
.device-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  border-top: 1px solid var(--line-soft);
}

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

.metric,
.device-grid > div {
  min-height: 86px;
  padding: 16px;
  border-right: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface-soft);
}

.metric:last-child,
.device-grid > div:nth-child(2n) {
  border-right: 0;
}

.metric-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric strong,
.device-grid strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 22px;
  line-height: 1.2;
}

.command-panel textarea,
.command-panel .form-row,
.command-panel .button-row {
  margin-right: 16px;
  margin-left: 16px;
}

textarea,
input {
  width: 100%;
  border: 1px solid #cfd6df;
  border-radius: 6px;
  padding: 10px 12px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
}

textarea:focus,
input:focus {
  border-color: var(--primary);
  outline: 3px solid rgb(37 99 235 / 14%);
}

textarea {
  min-height: 112px;
  resize: vertical;
}

label {
  flex: 1;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

label input {
  margin-top: 6px;
  color: var(--text);
  font-weight: 400;
}

.button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.button.primary {
  background: var(--primary);
  color: #ffffff;
}

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

.button.secondary {
  background: #ffffff;
  border-color: #cfd6df;
  color: #1f2937;
}

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

.button.compact {
  min-height: 32px;
  padding: 5px 10px;
  font-size: 13px;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
}

.badge::before {
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  content: "";
}

.badge.neutral {
  background: #eef2f6;
  color: #344054;
}

.badge.neutral::before {
  background: #98a2b3;
}

.badge.ok {
  background: #e7f6ef;
  color: var(--ok);
}

.badge.ok::before {
  background: var(--ok);
}

.badge.error {
  background: #fff0ed;
  color: var(--error);
}

.badge.error::before {
  background: var(--error);
}

.output {
  min-height: 174px;
  max-height: 390px;
  overflow: auto;
  margin: 14px 16px 16px;
  padding: 12px;
  border: 1px solid #1f2937;
  border-radius: 6px;
  background: var(--code);
  color: #e5eef8;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.output.small {
  min-height: 206px;
  max-height: 340px;
}

.table-wrap {
  overflow-x: auto;
  border-top: 1px solid var(--line-soft);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

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

th {
  background: var(--surface-soft);
  color: var(--muted);
  font-weight: 800;
}

td {
  overflow-wrap: anywhere;
}

dialog {
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 60px rgb(15 23 42 / 22%);
}

dialog::backdrop {
  background: rgb(16 24 40 / 48%);
}

.dialog-card {
  width: min(460px, calc(100vw - 28px));
  padding: 18px;
  background: #ffffff;
}

.dialog-card input {
  margin: 14px 0;
}

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

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

  .sidebar {
    position: static;
    height: auto;
    padding: 12px 16px;
  }

  .nav-list {
    display: flex;
    overflow-x: auto;
  }

  .sidebar-footer {
    display: none;
  }

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

  .status-panel,
  .command-panel,
  .table-panel,
  .device-panel,
  .messages-panel {
    grid-column: 1;
  }
}

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

  .topbar-actions,
  .button-row,
  .form-row {
    align-items: stretch;
    flex-direction: column;
    width: 100%;
  }

  .button,
  .badge {
    justify-content: center;
    width: 100%;
  }

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

  .metric,
  .device-grid > div {
    border-right: 0;
  }
}
