:root {
  color-scheme: light dark;
  --bg: #eef1f4;
  --bg-elev: #ffffff;
  --ink: #12151a;
  --muted: #6b7380;
  --line: rgba(18, 21, 26, 0.08);
  --accent: #0f9f86;
  --accent-ink: #ffffff;
  --danger: #e11d48;
  --ok: #0f9f86;
  --warn: #b45309;
  --shadow: 0 8px 24px rgba(18, 21, 26, 0.05);
  --radius: 16px;
  --radius-sm: 12px;
  --control-h: 48px;
  --page-pad: 16px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0d10;
    --bg-elev: #17181d;
    --ink: #f4f5f7;
    --muted: #9aa0ab;
    --line: rgba(255, 255, 255, 0.08);
    --accent: #2ee6a8;
    --accent-ink: #082019;
    --danger: #fb7185;
    --ok: #2ee6a8;
    --warn: #fbbf24;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.field {
  width: 100%;
  height: var(--control-h);
  border: 0;
  background: var(--bg-elev);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 0 16px;
  font-size: 16px;
  outline: none;
  box-shadow: var(--shadow);
}
.field:focus {
  box-shadow: 0 0 0 2px var(--accent), var(--shadow);
}
.lock-pass {
  -webkit-text-security: disc;
  text-security: disc;
}
.lock .field {
  background: var(--bg-elev);
  box-shadow: var(--shadow);
}
.sheet .field {
  background: var(--bg);
  box-shadow: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--control-h);
  border: 0;
  border-radius: var(--radius-sm);
  padding: 0 16px;
  font-weight: 650;
  cursor: pointer;
  background: transparent;
}
.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}
.btn-ghost {
  background: color-mix(in srgb, var(--ink) 7%, var(--bg-elev));
  color: var(--ink);
}
.btn-ghost.danger-text { color: var(--danger); }
.btn-text {
  min-height: 44px;
  padding: 8px 6px;
  color: var(--accent);
  font-weight: 600;
  font-size: 17px;
}
.btn-text.muted { color: var(--muted); }
.btn-danger {
  width: 100%;
  background: var(--bg-elev);
  color: var(--danger);
  box-shadow: var(--shadow);
}
.btn:disabled { opacity: 0.45; }

.lock {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(24px + env(safe-area-inset-top)) 28px calc(40px + env(safe-area-inset-bottom));
}
.lock-icon {
  width: 88px;
  height: 88px;
  border-radius: 22px;
  margin-bottom: 22px;
}
.lock h1 {
  margin: 0;
  font-size: 34px;
  letter-spacing: -0.04em;
}
.lock-sub {
  margin: 8px 0 28px;
  color: var(--muted);
}
.lock-form {
  width: min(100%, 340px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.lock-form .btn-primary { width: 100%; }
.lock-error {
  min-height: 1.4em;
  margin-top: 14px;
  color: var(--danger);
}

.nav {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: calc(8px + env(safe-area-inset-top)) var(--page-pad) 8px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 8px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(16px);
  -webkit-backdrop-filter: saturate(1.4) blur(16px);
}
.nav-text { min-width: 0; }
.nav h1 {
  margin: 0;
  font-size: 32px;
  letter-spacing: -0.04em;
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-kicker {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.nav-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  padding-bottom: 2px;
}
.nav-device {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  padding-bottom: 12px;
}
.nav-row {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
}
.back-arrow {
  flex: none;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  margin-left: -8px;
}
.nav-device h1 {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 28px;
  overflow: visible;
  white-space: nowrap;
}
.nav-device h1 #device-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.title-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-left: 36px;
}
.title-actions .btn {
  min-height: 40px;
  padding: 0 14px;
}

.page {
  padding: 8px var(--page-pad) calc(28px + env(safe-area-inset-bottom));
}
.section-label {
  margin: 22px 4px 8px;
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.group,
.table-wrap,
.empty,
.hint,
.danger-btn {
  background: var(--bg-elev);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row.stack { flex-direction: column; align-items: stretch; }
.row.between { justify-content: space-between; }
.row-main { min-width: 0; flex: 1; }
.row-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  font-size: 17px;
}
.row-sub,
.muted-row {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}
.row-sub {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.muted-row { white-space: normal; }
.device-row:active { background: color-mix(in srgb, var(--ink) 5%, var(--bg-elev)); }
.chevron { color: var(--muted); font-size: 22px; line-height: 1; }

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 650;
  background: color-mix(in srgb, var(--muted) 16%, transparent);
  color: var(--muted);
  flex: none;
}
.pill.on, .pill.sent { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.pill.failed { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.pill.skipped, .pill.pending, .pill.scheduled { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }

.url {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.45;
  word-break: break-all;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.row-actions,
.actions-row,
.sheet-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.row-actions .btn,
.actions-row .btn-primary,
.actions-row .btn-ghost { min-height: 40px; padding: 0 14px; }

.hint {
  color: var(--muted);
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.5;
  margin: 0 0 14px;
}
.hint.warn { color: var(--warn); }

.empty {
  padding: 36px 22px;
  text-align: center;
  color: var(--muted);
}
.empty.compact { padding: 22px; }
#history-empty {
  background: transparent;
  box-shadow: none;
  border-radius: 0;
}
.empty .btn-primary { margin-top: 8px; min-width: 160px; }

.search-field {
  margin-bottom: 10px;
  box-shadow: none;
  background: var(--bg-elev);
}

.push-form {
  padding: 12px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.push-field span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}
.push-field .field {
  background: var(--bg);
  box-shadow: none;
}
.push-form .btn-primary { width: 100%; }

.load-more {
  margin: 0;
  padding: 12px 16px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
#history-sentinel { height: 1px; }

.history {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.history thead { display: none; }
.history tr {
  display: block;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.history tr:last-child { border-bottom: 0; }
.history td {
  display: block;
  padding: 0;
  border: 0;
  word-break: break-word;
}
.history td + td { margin-top: 6px; }
.history td[data-label="时间"] { color: var(--muted); font-size: 12px; }
.history td[data-label="标题"] { font-weight: 650; font-size: 16px; }
.history td[data-label="内容"] { color: var(--muted); }
.history .err { margin-top: 4px; color: var(--danger); font-size: 12px; }

.danger-btn {
  display: block;
  width: 100%;
  margin-top: 28px;
  border: 0;
  background: var(--bg-elev);
  color: var(--danger);
  border-radius: var(--radius);
  padding: 16px;
  font-weight: 650;
  cursor: pointer;
}

.sheet {
  width: min(calc(100% - 32px), 400px);
  border: 0;
  border-radius: 20px;
  padding: 22px 18px 16px;
  background: var(--bg-elev);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
}
.sheet::backdrop { background: rgba(12, 13, 16, 0.48); }
.sheet h2 { margin: 0 0 6px; font-size: 20px; letter-spacing: -0.02em; }
.sheet p { margin: 0 0 16px; color: var(--muted); font-size: 14px; line-height: 1.45; }
.sheet label {
  display: block;
  font-size: 13px;
  font-weight: 650;
  color: var(--muted);
  margin-bottom: 6px;
}
.sheet .field { margin-bottom: 16px; }
.sheet-actions { justify-content: flex-end; }
.sheet-actions .btn { min-height: 40px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  z-index: 40;
}

.shake { animation: shake 0.36s; }
@keyframes shake {
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
