:root {
  --paper: #eef1f0;
  --panel: #f9faf9;
  --ink: #16232a;
  --ink-soft: #5a6b70;
  --line: #cbd5d2;
  --teal: #0e5a66;
  --teal-deep: #0a4149;
  --amber: #a85b00;
  --red: #9b2c2c;
  --ok: #2f6b4f;
  --radius-sm: 6px;
  --radius-lg: 10px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 14px;
  line-height: 1.57;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 26px; line-height: 34px; }
h2 { font-size: 16px; line-height: 24px; }

.skip {
  position: absolute;
  left: -9999px;
}
.skip:focus {
  left: 12px;
  top: 12px;
  z-index: 20;
  padding: 8px 12px;
  background: var(--panel);
  border: 2px solid var(--teal);
  border-radius: var(--radius-sm);
}

:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------- login */

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

.login-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: 0 1px 2px rgba(22, 35, 42, 0.06), 0 8px 24px rgba(22, 35, 42, 0.06);
}

.login-card h1 { margin-bottom: 4px; }
.login-card .muted { margin: 0 0 24px; }

label {
  display: block;
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

input, select {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  margin-bottom: 16px;
}

input:focus, select:focus {
  border-color: var(--teal);
  outline-offset: 1px;
}

/* ---------------------------------------------------------------- shell */

#app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px 64px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 0 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 24px;
}

.brand {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-soft);
}
.dot.online { background: var(--ok); }
.dot.offline { background: var(--red); }

.status-text { font-size: 13px; color: var(--ink-soft); }
.version { font-size: 12px; color: var(--ink-soft); }

.section-title {
  margin: 32px 0 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.section-title.with-action { justify-content: space-between; }

.muted { color: var(--ink-soft); }
.small { font-size: 13px; }
.error-line { color: var(--red); font-size: 13px; margin: 0; }

/* --------------------------------------------------------------- device */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: 0 1px 2px rgba(22, 35, 42, 0.06), 0 8px 24px rgba(22, 35, 42, 0.06);
}

.device-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
}

.device-id {
  font-size: 22px;
  line-height: 30px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.device-readout {
  font-size: 48px;
  line-height: 52px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--teal);
}

.timebar {
  position: relative;
  height: 14px;
  margin: 20px 0 8px;
  background: #dfe5e3;
  border-radius: 7px;
  overflow: hidden;
}

.timebar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: var(--teal);
  border-radius: 7px;
  transform-origin: left center;
  transition: width 400ms cubic-bezier(0.2, 0.7, 0.2, 1), background-color 200ms linear;
}
.timebar-fill.warn { background: var(--amber); }

.timebar-ticks {
  position: absolute;
  inset: 0;
  background-image: repeating-linear-gradient(
    to right,
    transparent 0,
    transparent calc(10% - 1px),
    rgba(22, 35, 42, 0.16) calc(10% - 1px),
    rgba(22, 35, 42, 0.16) 10%
  );
}

.device-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
}

/* --------------------------------------------------------------- tables */

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow-x: auto;
}

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

th, td {
  text-align: left;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

th {
  font-weight: 600;
  color: var(--ink-soft);
  font-size: 12px;
}

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

td.wrap {
  white-space: normal;
  word-break: break-word;
}

.empty {
  margin: 0;
  padding: 20px 16px;
  font-size: 13px;
  color: var(--ink-soft);
}

/* ---------------------------------------------------------------- events */

.events {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.events li {
  display: flex;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.events li:last-child { border-bottom: 0; }
.events li.warn {
  border-left: 3px solid var(--amber);
  padding-left: 13px;
}
.events time {
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}
.events .action {
  color: var(--teal);
  flex: 0 0 72px;
}
.events .detail {
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- inputs */

.filters {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.filters label { margin: 0; }
.filters select { width: auto; margin: 0; }

.pager {
  display: flex;
  justify-content: center;
  padding: 16px 0;
}

/* --------------------------------------------------------------- buttons */

.btn {
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  cursor: pointer;
  transition: background-color 120ms linear, border-color 120ms linear;
}
.btn:hover { background: #e4e9e7; }
.btn:active { background: #d8e0dd; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.ghost { border-color: transparent; color: var(--teal); }
.btn.ghost:hover { background: #e2e9e7; }
.btn.primary {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}
.btn.primary:hover { background: var(--teal-deep); border-color: var(--teal-deep); }
.btn.danger { color: var(--red); border-color: #d8c2c2; }
.btn.danger:hover { background: #f2e4e4; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }

/* --------------------------------------------------------------- dialogs */

dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px;
  background: var(--panel);
  color: var(--ink);
  width: min(440px, calc(100vw - 32px));
  box-shadow: 0 8px 32px rgba(22, 35, 42, 0.18);
}
dialog::backdrop { background: rgba(22, 35, 42, 0.32); }
dialog h2 { margin-bottom: 12px; }
dialog p { margin-top: 0; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.secret-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}
.secret-row code {
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  word-break: break-all;
}

/* ----------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  z-index: 30;
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 759px) {
  #app { padding: 0 16px 48px; }
  .device-readout { font-size: 34px; line-height: 40px; }
  .timebar-ticks { display: none; }
  .device-head { flex-direction: column; gap: 8px; }
  th, td { padding: 8px 12px; }
  .events li { flex-wrap: wrap; gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------------------------------------------------------------- debug */

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.tab {
  appearance: none;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 8px 14px;
  font: inherit;
  font-size: 14px;
  color: var(--ink-soft);
  cursor: pointer;
}

.tab:hover { color: var(--ink); }

.tab.active {
  color: var(--teal);
  border-bottom-color: var(--teal);
  font-weight: 600;
}

.tab:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: -2px;
}

.tab-panel { display: block; }
.tab-panel[hidden] { display: none; }

.debug-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.debug-title {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.debug-title + .debug-actions,
.debug-actions + .debug-title {
  margin-top: 20px;
}

.debug-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 20px;
}

.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 16px;
  margin: 0 0 4px;
  font-size: 13px;
}

.kv dt { color: var(--ink-soft); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

.plain-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 13px;
}

.plain-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.plain-list li:last-child { border-bottom: 0; }

.plain-list .meta {
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.kv .ok { color: var(--ok); }
.kv .bad { color: var(--red); }

@media (max-width: 759px) {
  .debug-grid { grid-template-columns: 1fr; }
  .tabs { overflow-x: auto; }
}

/* ------------------------------------------------------------- integrate */

.code-block {
  margin: 12px 0 0;
  padding: 16px;
  background: #0f1a1f;
  color: #d7e3e6;
  border-radius: var(--radius-sm);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.7;
  overflow-x: auto;
  white-space: pre;
}

.integrate-group { margin-bottom: 20px; }
.integrate-group:last-child { margin-bottom: 0; }
.integrate-group h3 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--teal);
  letter-spacing: 0.02em;
}
.integrate-group ul { margin: 0; padding: 0; list-style: none; }
.integrate-group li {
  display: flex;
  gap: 12px;
  padding: 5px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.integrate-group li:last-child { border-bottom: 0; }
.integrate-group code {
  flex: 0 0 168px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--ink);
}
.integrate-group span { color: var(--ink-soft); }
.integrate-group .muted { color: var(--ink-soft); }
