:root {
  color-scheme: light;
  --page-pad: clamp(10px, 3.8vw, 18px);
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --line: #d9e1ea;
  --text: #17202a;
  --muted: #657485;
  --accent: #0b7a75;
  --accent-soft: #e6f5f2;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --ok: #167348;
  --warning: #a15c07;
  --shadow: 0 10px 24px rgba(17, 24, 39, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  padding-bottom: calc(78px + env(safe-area-inset-bottom));
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(100vw, 760px);
  margin: 0 auto;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) var(--page-pad) 10px;
  background: rgba(243, 245, 247, 0.96);
  border-bottom: 1px solid rgba(217, 225, 234, 0.8);
  backdrop-filter: blur(12px);
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

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

h1 {
  font-size: clamp(19px, 5.6vw, 22px);
  line-height: 1.2;
}

h2 {
  font-size: clamp(16px, 4.6vw, 17px);
}

h3 {
  font-size: 15px;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  font-weight: 800;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 10px var(--page-pad) 4px;
}

.metric-strip div {
  min-width: 0;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 8px;
}

.metric-strip b {
  display: block;
  font-size: clamp(17px, 5.2vw, 20px);
  line-height: 1.15;
}

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

.view-root {
  padding: 10px var(--page-pad) 18px;
}

.site-footer {
  padding: 8px var(--page-pad) 18px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.site-footer a {
  color: inherit;
  text-decoration: none;
}

[hidden] {
  display: none !important;
}

.stack {
  display: grid;
  gap: 12px;
}

.auth-wrap {
  min-height: calc(100dvh - 96px);
  display: grid;
  align-items: start;
  padding-top: 8vh;
}

.auth-card {
  width: 100%;
}

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

.card-body {
  padding: clamp(12px, 3.8vw, 16px);
}

.card-button {
  width: 100%;
  display: block;
  text-align: left;
  color: inherit;
  background: var(--surface);
}

.card-button:active {
  background: var(--surface-soft);
}

.device-card {
  display: grid;
}

.device-open {
  border-radius: 0;
}

.card-actions {
  padding: 0 clamp(12px, 3.8vw, 16px) clamp(12px, 3.8vw, 16px);
}

.compact-btn {
  width: 100%;
  min-height: 38px;
}

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

.row-start {
  display: flex;
  align-items: center;
  gap: 10px;
}

.title-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.mono {
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #a8b3c0;
  flex: 0 0 auto;
}

.status-dot.online {
  background: var(--ok);
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 9px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.pill.ok {
  background: #e8f6ee;
  color: var(--ok);
}

.pill.warn {
  background: #fff7ed;
  color: var(--warning);
}

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

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px 0;
  min-width: 0;
}

.section-title h2,
.title-line strong,
.title-line h2 {
  min-width: 0;
  overflow-wrap: anywhere;
}

.section-title span {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
  overflow-wrap: anywhere;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.segmented button {
  min-height: 38px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.segmented button.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.search {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--surface);
}

.primary-btn,
.secondary-btn,
.danger-btn,
.ghost-btn {
  min-height: 46px;
  border-radius: 8px;
  padding: 0 13px;
  font-weight: 800;
  line-height: 1.25;
}

.primary-btn {
  background: var(--accent);
  color: #fff;
}

.secondary-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
}

.danger-btn {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #f1b9b4;
}

.ghost-btn {
  background: transparent;
  color: var(--accent);
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.button-grid.single {
  grid-template-columns: 1fr;
}

.form-grid {
  display: grid;
  gap: 10px;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

input,
select {
  height: 46px;
  padding: 0 12px;
}

textarea {
  min-height: 96px;
  padding: 10px 12px;
  resize: vertical;
  line-height: 1.5;
}

.toggle-list,
.check-grid {
  display: grid;
  gap: 8px;
}

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

.check-item {
  min-height: 46px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.detail-header {
  display: grid;
  gap: 10px;
}

.back-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

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

.kv div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 10px;
}

.kv b {
  display: block;
  font-size: 14px;
  overflow-wrap: anywhere;
}

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

.task-row,
.audit-row,
.rule-row {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
}

.task-row strong,
.audit-row strong,
.rule-row strong {
  font-size: 14px;
}

.empty {
  padding: 28px 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  background: var(--surface);
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 30;
  width: min(100vw, 760px);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 7px var(--page-pad) calc(7px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
}

.nav-btn {
  min-width: 0;
  height: 48px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  font-size: 14px;
}

.nav-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  z-index: 50;
  transform: translateX(-50%) translateY(20px);
  width: min(calc(100% - 32px), 520px);
  padding: 12px 14px;
  border-radius: 8px;
  background: rgba(23, 32, 42, 0.94);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  font-size: 14px;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (min-width: 680px) {
  .view-root {
    padding-bottom: 28px;
  }

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

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

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

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

  .kv {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (min-width: 430px) {
  .toolbar {
    grid-template-columns: 1fr auto;
  }
}

@media (max-width: 380px) {
  .metric-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .metric-strip div {
    padding: 7px 6px;
  }

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

  .nav-btn {
    font-size: 13px;
  }
}
