:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --surface: #ffffff;
  --ink: #17201c;
  --muted: #647067;
  --line: #dfe5dc;
  --green: #14805e;
  --green-soft: #e4f3ec;
  --amber: #a66a00;
  --amber-soft: #fff2d6;
  --red: #b42318;
  --red-soft: #ffe4df;
  --teal: #0f6b78;
  --shadow: 0 18px 50px rgba(33, 48, 40, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
  min-width: 0;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px;
  background: #edf1ea;
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 30px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-weight: 800;
}

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

.brand span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav a {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
}

.nav a:hover,
.nav a.active {
  background: var(--surface);
  color: var(--ink);
}

.local-note {
  margin-top: 28px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--muted);
  line-height: 1.6;
}

.workspace {
  display: grid;
  gap: 18px;
  padding: 26px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 4px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.18;
}

h2 {
  font-size: 18px;
  line-height: 1.25;
}

.topbar p,
.panel-heading p {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.5;
}

.topbar-actions,
.panel-heading,
.sub-heading,
.command-bar,
.protocol-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.panel-heading {
  justify-content: space-between;
  margin-bottom: 16px;
}

.sub-heading {
  justify-content: space-between;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

h3 {
  margin: 0;
  font-size: 15px;
}

.section-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(360px, 0.88fr);
  gap: 18px;
}

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

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

.device-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  width: 100%;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.device-row:hover,
.device-row.selected {
  border-color: rgba(20, 128, 94, 0.55);
  background: var(--green-soft);
}

.device-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.device-title strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meta,
.detail-grid span,
.timeline small,
.event-list small {
  color: var(--muted);
  font-size: 12px;
}

.status-badge,
.count,
.chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 700;
}

.status-badge.ok,
.chip.ok {
  background: var(--green-soft);
  color: var(--green);
  border-color: rgba(20, 128, 94, 0.2);
}

.status-badge.neutral,
.chip.neutral,
.count {
  background: #eef2f7;
  color: #475467;
}

.chip.warn {
  background: var(--amber-soft);
  color: var(--amber);
}

.chip.danger {
  background: var(--red-soft);
  color: var(--red);
}

.detail-empty {
  display: grid;
  min-height: 240px;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.detail-empty.small {
  min-height: 86px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.summary-metric {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  color: var(--muted);
}

.metric {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
}

.button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--green);
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.button:hover {
  filter: brightness(0.97);
}

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

.button.tiny {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.button.warning {
  background: var(--amber);
  border-color: var(--amber);
}

.button.danger {
  background: var(--red);
  border-color: var(--red);
}

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

.command-bar {
  flex-wrap: wrap;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.protocol-actions {
  flex-wrap: wrap;
}

.protocol-actions code {
  flex: 1 1 260px;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 10px;
  align-items: end;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.filter-field {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.filter-field.wide {
  grid-column: span 2;
}

.filter-field input,
.filter-field select {
  min-height: 38px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
  outline: 0;
}

.filter-check {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.filter-check input {
  width: 16px;
  height: 16px;
}

.filter-actions {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  grid-column: span 2;
}

.inline-field {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  gap: 8px;
  padding-left: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
}

.inline-field input,
.inline-field select {
  width: 72px;
  min-height: 36px;
  border: 0;
  border-left: 1px solid var(--line);
  padding: 0 10px;
  outline: 0;
}

.inline-field select {
  width: min(360px, 52vw);
  background: #fff;
}

.timeline,
.event-list,
.recovery-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.timeline.compact {
  margin-top: 10px;
}

.timeline-item,
.event-item,
.recovery-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.timeline-item > div:first-child,
.event-item > div:first-child,
.schedule-item > div:first-child {
  min-width: 0;
}

.timeline-item strong,
.timeline-item small,
.event-item strong,
.event-item small,
.schedule-item strong,
.schedule-item small {
  overflow-wrap: anywhere;
}

.recovery-item-main {
  min-width: 0;
}

.recovery-item-main strong,
.recovery-item-main small {
  display: block;
}

.recovery-tags {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.row-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.schedule-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.schedule-toolbar code {
  flex: 1 1 auto;
}

.schedule-item {
  align-items: start;
}

.schedule-actions {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
  max-width: 360px;
}

.schedule-trace {
  display: grid;
  gap: 7px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}

.schedule-command-row {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 8px;
}

.schedule-event-row {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 8px;
}

.schedule-command-row small,
.schedule-event-row small,
.schedule-log-row {
  min-width: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.schedule-log-row {
  display: block;
}

.credential-actions {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.maintenance-alert-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.maintenance-alert {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.maintenance-alert strong,
.maintenance-alert small {
  display: block;
}

.maintenance-alert small {
  margin-top: 4px;
  color: var(--muted);
}

.maintenance-alert.ok {
  border-color: rgba(20, 128, 94, 0.2);
  background: var(--green-soft);
}

.maintenance-alert.warn {
  border-color: rgba(166, 106, 0, 0.25);
  background: var(--amber-soft);
}

.maintenance-alert.danger {
  border-color: rgba(180, 35, 24, 0.25);
  background: var(--red-soft);
}

.mini-button {
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.mini-button:hover {
  border-color: rgba(20, 128, 94, 0.5);
  color: var(--green);
}

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

.adapter-flow {
  display: grid;
  grid-template-columns: repeat(6, minmax(100px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.adapter-flow span,
.adapter-flow b {
  min-height: 52px;
  display: grid;
  place-items: center;
  padding: 8px;
  border-radius: 8px;
  text-align: center;
}

.adapter-flow span {
  background: #f5f7f2;
  border: 1px solid var(--line);
}

.adapter-flow b {
  background: #e1f0ef;
  color: var(--teal);
}

code {
  overflow-wrap: anywhere;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f6f7f3;
  color: #33423b;
}

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

  .sidebar {
    position: static;
    height: auto;
  }

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

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

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

@media (max-width: 620px) {
  .workspace,
  .sidebar {
    padding: 16px;
  }

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

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

  .timeline-item,
  .event-item,
  .recovery-item,
  .device-row {
    grid-template-columns: 1fr;
  }

  .recovery-tags {
    justify-content: flex-start;
  }

  .schedule-actions {
    justify-content: flex-start;
    max-width: none;
  }

  .schedule-command-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .schedule-event-row {
    align-items: flex-start;
    flex-direction: column;
  }
}
