/* ==========================================================================
   Agent 远程看护台 —— 移动端样式
   硬性规范：正文 >=16px、状态数字 28px、行高 1.6、触控 >=44x44px、
            主操作在屏幕下半部、跟随系统深色模式、安全区 env(safe-area-inset-*)
   ========================================================================== */

:root {
  color-scheme: light dark;

  --bg: #f3f6fc;
  --bg-deep: #e8eefa;
  --surface: #ffffff;
  --surface-2: #f1f5fb;
  --surface-3: #e7eef8;
  --text: #11182a;
  --text-dim: #4b5566;
  --text-faint: #5f6b80;
  --border: #d5dfec;
  --border-strong: #b9c7db;

  --brand: #1d4ed8;
  --brand-soft: #dbe7ff;
  --brand-ink: #ffffff;
  --focus: #2563eb;

  --ok: #047857;
  --ok-soft: #d7f5e7;
  --warn: #b45309;
  --warn-soft: #fdecd3;
  --danger: #b91c1c;
  --danger-soft: #fde2e1;
  --info: #0e7490;
  --info-soft: #d8f1f8;
  --muted-soft: #e5e9f1;

  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --tap: 44px;

  --shadow-1: 0 1px 2px rgba(15, 30, 55, 0.06), 0 6px 18px rgba(15, 30, 55, 0.07);
  --shadow-2: 0 8px 28px rgba(15, 30, 55, 0.18);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);

  --tabbar-h: 64px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a1220;
    --bg-deep: #060d18;
    --surface: #141f33;
    --surface-2: #1b2841;
    --surface-3: #223252;
    --text: #e9eefb;
    --text-dim: #aab6cd;
    --text-faint: #94a3bd;
    --border: #2a3a58;
    --border-strong: #3b4f73;

    --brand: #7aa7ff;
    --brand-soft: #1d3054;
    --brand-ink: #08111f;
    --focus: #8ab4ff;

    --ok: #34d399;
    --ok-soft: #10382c;
    --warn: #fbbf24;
    --warn-soft: #3d2c10;
    --danger: #f87171;
    --danger-soft: #451d1f;
    --info: #67e8f9;
    --info-soft: #0d3540;
    --muted-soft: #24314a;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.28);
    --shadow-2: 0 10px 34px rgba(0, 0, 0, 0.55);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

#main {
  flex: 1 1 auto;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 8px) calc(12px + var(--safe-right)) 24px
    calc(12px + var(--safe-left));
}

/* 有底部标签栏的页面要给标签栏留位置 */
.view.has-tabbar {
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
}

/* 详情页给固定输入条留位置（输入条自身高度由 JS 变量给出） */
.view.is-detail {
  padding-bottom: calc(var(--composer-h, 190px) + var(--safe-bottom) + 16px);
}

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

button {
  font: inherit;
  color: inherit;
}

a {
  color: var(--brand);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

/* 所有可点元素最小 44x44 */
button,
select,
input[type="text"],
input[type="tel"],
input[type="number"],
a.btn {
  min-height: var(--tap);
}

button {
  min-width: var(--tap);
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  font-size: 16px;
  line-height: 1.4;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.15s ease, border-color 0.15s ease,
    transform 0.06s ease;
}

button:active:not(:disabled) {
  transform: scale(0.985);
}

button:disabled,
button[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
  font-weight: 700;
}

.btn-danger {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
  font-weight: 700;
}

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

.btn-lg {
  min-height: 52px;
  font-size: 17px;
  font-weight: 700;
}

/* --------------------------------------------------------------------------
   顶部栏 / 连接状态 / 离线横幅
   -------------------------------------------------------------------------- */

.appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-top);
}

.appbar-inner {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  min-height: 56px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px calc(12px + var(--safe-right)) 6px calc(12px + var(--safe-left));
}

.appbar h1 {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.01em;
  line-height: 1.3;
}

.appbar .brand-mark {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 10px;
  background: linear-gradient(135deg, #1d4ed8, #0891b2);
  position: relative;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand) 26%, transparent);
}

.appbar .brand-mark::after {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 50%;
  border: 3px solid #e0f2fe;
  box-shadow: inset 0 0 0 3px rgba(34, 211, 238, 0.55);
}

.appbar .spacer {
  flex: 1 1 auto;
}

.appbar-sub {
  display: block;
  font-size: 16px;
  font-weight: 400;
  color: var(--text-dim);
}

.icon-btn {
  min-height: var(--tap);
  min-width: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 16px;
}

.conn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 16px;
  line-height: 1.3;
  color: var(--text-dim);
  white-space: nowrap;
}

.conn-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--text-faint);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--text-faint) 22%, transparent);
}

.conn[data-state="online"] {
  color: var(--ok);
}
.conn[data-state="online"] .conn-dot {
  background: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 24%, transparent);
}
.conn[data-state="connecting"] {
  color: var(--warn);
}
.conn[data-state="connecting"] .conn-dot {
  background: var(--warn);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 24%, transparent);
  animation: pulse 1.4s ease-in-out infinite;
}
.conn[data-state="offline"] {
  color: var(--danger);
}
.conn[data-state="offline"] .conn-dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 24%, transparent);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

.banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 10px 0 0;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 16px;
  line-height: 1.6;
}

.banner strong {
  font-weight: 700;
}

.banner--offline {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
  background: var(--danger-soft);
  color: var(--text);
}

.banner--warn {
  border-color: color-mix(in srgb, var(--warn) 45%, var(--border));
  background: var(--warn-soft);
  color: var(--text);
}

.banner--info {
  border-color: color-mix(in srgb, var(--info) 40%, var(--border));
  background: var(--info-soft);
  color: var(--text);
}

.banner .banner-icon {
  font-size: 18px;
  line-height: 1.6;
}

/* --------------------------------------------------------------------------
   看板：统计 / 分段筛选 / 任务卡
   -------------------------------------------------------------------------- */

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 6px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow-1);
  min-height: 96px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}

.stat-label {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-value {
  font-size: 28px;
  line-height: 1.2;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.stat--pending .stat-value {
  color: var(--warn);
}
.stat--running .stat-value {
  color: var(--ok);
}

.stat-badge {
  display: inline-block;
  min-width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 20%, transparent);
}

.stat-badge[data-empty="1"] {
  background: var(--border-strong);
  box-shadow: none;
}

.stat-hint {
  font-size: 16px;
  color: var(--text-faint);
}

.segmented {
  display: flex;
  gap: 8px;
  margin: 16px 0 4px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.segmented button {
  flex: 1 1 0;
  min-height: var(--tap);
  border: 0;
  border-radius: 999px;
  background: transparent;
  padding: 8px 10px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-dim);
}

.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-1);
}

.list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 18px 2px 8px;
}

.list-head h2 {
  font-size: 18px;
  font-weight: 800;
}

.list-head .count {
  font-size: 16px;
  color: var(--text-faint);
}

.task-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.task-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 14px 14px 14px 16px;
  position: relative;
  overflow: hidden;
}

.task-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  background: var(--border-strong);
}

.task-card[data-status="needs_reply"]::before,
.task-card[data-status="needs_input"]::before {
  background: var(--warn);
}
.task-card[data-status="running"]::before {
  background: var(--ok);
}
.task-card[data-status="failed"]::before {
  background: var(--danger);
}
.task-card[data-status="paused"]::before {
  background: var(--info);
}
.task-card[data-pending="1"] {
  border-color: color-mix(in srgb, var(--warn) 40%, var(--border));
}

.task-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: none;
  border: 0;
  padding: 0;
  min-height: var(--tap);
  text-align: left;
  color: inherit;
  border-radius: var(--radius-sm);
}

.task-main:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.task-top {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  justify-content: space-between;
}

.task-title {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.45;
  word-break: break-word;
  margin: 0;
}

.task-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  font-size: 16px;
  color: var(--text-dim);
  line-height: 1.6;
}

.task-meta .agent-name {
  font-weight: 600;
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-meta .sep {
  color: var(--border-strong);
}

.task-meta .waited {
  color: var(--warn);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.task-summary {
  font-size: 16px;
  color: var(--text-dim);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.task-side {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
}

.task-side .btn-reply {
  min-width: 64px;
  min-height: var(--tap);
  background: var(--brand-soft);
  border-color: color-mix(in srgb, var(--brand) 45%, var(--border));
  color: var(--brand);
  font-weight: 800;
  padding: 8px 12px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
  min-height: 30px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.4;
  border: 1px solid transparent;
  white-space: nowrap;
}

.chip--queued,
.chip--closed,
.chip--cancelled {
  background: var(--muted-soft);
  color: var(--text-dim);
  border-color: var(--border);
}
.chip--running {
  background: var(--ok-soft);
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 35%, transparent);
}
.chip--needs_reply,
.chip--needs_input {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 35%, transparent);
}
.chip--failed {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
}
.chip--paused {
  background: var(--info-soft);
  color: var(--info);
  border-color: color-mix(in srgb, var(--info) 35%, transparent);
}

.priority-flag {
  font-size: 16px;
  font-weight: 700;
  color: var(--danger);
  border: 1px solid currentColor;
  border-radius: 8px;
  padding: 1px 6px;
  line-height: 1.4;
}

/* 空状态 / 骨架屏 */
.empty {
  margin-top: 18px;
  padding: 28px 20px;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  color: var(--text-dim);
  font-size: 16px;
}

.empty h2 {
  font-size: 18px;
  color: var(--text);
  margin-bottom: 6px;
}

.empty p + p {
  margin-top: 8px;
}

.skeleton-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.skeleton {
  border-radius: var(--radius-lg);
  background: linear-gradient(
    100deg,
    var(--surface-2) 20%,
    var(--surface-3) 42%,
    var(--surface-2) 64%
  );
  background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite;
  border: 1px solid var(--border);
}

.skeleton--card {
  height: 120px;
}
.skeleton--stat {
  height: 96px;
}
.skeleton--line {
  height: 20px;
  border-radius: 8px;
}

@keyframes shimmer {
  0% {
    background-position: 140% 0;
  }
  100% {
    background-position: -40% 0;
  }
}

.boot {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 70vh;
  padding: 20px;
}

.boot-card {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 17px;
  color: var(--text-dim);
}

.boot-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--brand);
  animation: pulse 1.2s ease-in-out infinite;
}

.noscript {
  max-width: 720px;
  margin: 40px auto;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  font-size: 16px;
}

.noscript h1 {
  font-size: 20px;
  margin-bottom: 8px;
}

/* --------------------------------------------------------------------------
   配对页
   -------------------------------------------------------------------------- */

.pair-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 24px) calc(16px + var(--safe-right))
    calc(var(--safe-bottom) + 24px) calc(16px + var(--safe-left));
}

.pair-card {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow-2);
  padding: 24px 20px 20px;
}

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

.pair-brand h1 {
  font-size: 21px;
  font-weight: 800;
  line-height: 1.35;
}

.pair-lead {
  font-size: 16px;
  color: var(--text-dim);
  line-height: 1.6;
  margin: 4px 0 18px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.field label {
  font-size: 16px;
  font-weight: 700;
}

.field .hint {
  font-size: 16px;
  color: var(--text-faint);
  line-height: 1.6;
}

.input {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 17px;
  line-height: 1.6;
  appearance: none;
}

.input:focus {
  outline: 3px solid color-mix(in srgb, var(--focus) 55%, transparent);
  outline-offset: 1px;
  border-color: var(--focus);
}

.input--code {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.42em;
  text-align: center;
  font-variant-numeric: tabular-nums;
  padding-left: 0.42em;
}

.pair-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

.pair-error {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--border));
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
}

.pair-help {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 16px;
  color: var(--text-dim);
  line-height: 1.6;
}

.pair-help ol {
  margin: 8px 0 0;
  padding-left: 22px;
}

.pair-help li + li {
  margin-top: 4px;
}

.pair-help code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 5px;
}

/* --------------------------------------------------------------------------
   详情页
   -------------------------------------------------------------------------- */

.detail-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.back-btn {
  background: var(--surface-2);
  padding: 6px 14px 6px 10px;
  border-radius: 999px;
  font-weight: 700;
}

.detail-title-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 4px 0 12px;
}

.detail-title {
  font-size: 20px;
  font-weight: 800;
  line-height: 1.4;
  word-break: break-word;
}

.detail-sub {
  font-size: 16px;
  color: var(--text-dim);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  line-height: 1.6;
}

.statusbar {
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  display: flex;
  align-items: center;
  gap: 12px;
}

.statusbar .status-emoji {
  font-size: 24px;
  line-height: 1.2;
}

.statusbar .status-text {
  flex: 1 1 auto;
  min-width: 0;
}

.statusbar .status-label {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.4;
}

.statusbar .status-hint {
  font-size: 16px;
  color: var(--text-dim);
  line-height: 1.6;
}

.statusbar[data-status="running"] {
  border-color: color-mix(in srgb, var(--ok) 45%, var(--border));
  background: color-mix(in srgb, var(--ok-soft) 70%, var(--surface));
}
.statusbar[data-status="needs_reply"],
.statusbar[data-status="needs_input"] {
  border-color: color-mix(in srgb, var(--warn) 50%, var(--border));
  background: color-mix(in srgb, var(--warn-soft) 75%, var(--surface));
}
.statusbar[data-status="failed"] {
  border-color: color-mix(in srgb, var(--danger) 50%, var(--border));
  background: color-mix(in srgb, var(--danger-soft) 75%, var(--surface));
}
.statusbar[data-status="paused"] {
  border-color: color-mix(in srgb, var(--info) 45%, var(--border));
  background: color-mix(in srgb, var(--info-soft) 70%, var(--surface));
}
.statusbar[data-status="closed"],
.statusbar[data-status="cancelled"],
.statusbar[data-status="queued"] {
  background: var(--surface);
}

.statusbar .waited-pill {
  flex: 0 0 auto;
  font-size: 16px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--warn);
  background: var(--warn-soft);
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  border-radius: 999px;
  padding: 4px 12px;
}

.section {
  margin-top: 22px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.section-head h2 {
  font-size: 18px;
  font-weight: 800;
}

.section-head .count {
  font-size: 16px;
  color: var(--text-faint);
}

.section-toggle {
  min-height: var(--tap);
  padding: 6px 14px;
  font-size: 16px;
  border-radius: 999px;
  background: var(--surface-2);
}

.events {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.events.collapsed .event:nth-last-child(n + 4) {
  display: none;
}

.event {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 16px;
  line-height: 1.6;
}

.event-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 2px;
}

.event-type {
  font-weight: 800;
}

.event-actor {
  font-size: 16px;
  color: var(--text-faint);
}

.event-time {
  margin-left: auto;
  font-size: 16px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.event-body {
  color: var(--text-dim);
  word-break: break-word;
  white-space: pre-wrap;
}

.event[data-actor="user"] .event-type {
  color: var(--brand);
}
.event[data-actor="system"] .event-type {
  color: var(--text-dim);
}

/* 对话气泡 */
.messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 88%;
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 16px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
  border: 1px solid var(--border);
  background: var(--surface);
}

.msg-meta {
  font-size: 16px;
  color: var(--text-faint);
  padding: 0 4px;
}

.msg--agent {
  align-self: flex-start;
  align-items: flex-start;
}
.msg--agent .msg-bubble {
  border-bottom-left-radius: 6px;
}

.msg--user {
  align-self: flex-end;
  align-items: flex-end;
}
.msg--user .msg-bubble {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
  border-bottom-right-radius: 6px;
}

.msg--pending {
  opacity: 0.7;
}

.msg--failed .msg-bubble {
  border-color: var(--danger);
}

.msg-failed-note {
  font-size: 16px;
  color: var(--danger);
  padding: 0 4px;
}

/* 任务操作区 */
.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.action-grid button {
  min-height: 52px;
  font-weight: 700;
}

.action-note {
  margin-top: 8px;
  font-size: 16px;
  color: var(--text-faint);
  line-height: 1.6;
}

/* --------------------------------------------------------------------------
   底部固定输入条（详情页，拇指区）
   -------------------------------------------------------------------------- */

.composer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  box-shadow: 0 -6px 24px rgba(10, 20, 40, 0.08);
  padding: 8px calc(10px + var(--safe-right))
    calc(8px + var(--safe-bottom)) calc(10px + var(--safe-left));
}

.composer-inner {
  max-width: 720px;
  margin: 0 auto;
}

.phrase-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 6px;
  scrollbar-width: none;
}

.phrase-row::-webkit-scrollbar {
  display: none;
}

.phrase {
  flex: 0 0 auto;
  min-height: var(--tap);
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-weight: 600;
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.reply-input {
  flex: 1 1 auto;
  min-height: var(--tap);
  max-height: 132px;
  resize: none;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 17px;
  line-height: 1.6;
  overflow-y: auto;
}

.reply-input:focus {
  outline: 3px solid color-mix(in srgb, var(--focus) 55%, transparent);
  outline-offset: 1px;
  border-color: var(--focus);
}

.btn-send {
  flex: 0 0 auto;
  min-width: 80px;
  min-height: 48px;
  font-size: 17px;
  font-weight: 800;
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
  border-radius: var(--radius-md);
}

.btn-send[data-busy="1"] {
  opacity: 0.7;
}

.composer-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
  padding-top: 6px;
  font-size: 16px;
  color: var(--text-faint);
  line-height: 1.4;
  min-height: 24px;
}

.composer-foot .send-error {
  color: var(--danger);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.composer-foot .send-error button {
  min-height: var(--tap);
  padding: 4px 12px;
  font-size: 16px;
}

.composer-foot .kbd-hint {
  margin-left: auto;
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   底部标签栏
   -------------------------------------------------------------------------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 35;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}

.tabbar-inner {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  height: var(--tabbar-h);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

.tab {
  flex: 1 1 0;
  min-height: var(--tap);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  background: transparent;
  border-radius: 0;
  color: var(--text-dim);
  font-size: 16px;
  font-weight: 600;
  position: relative;
  padding: 4px;
}

.tab[aria-current="page"] {
  color: var(--brand);
  background: transparent;
}

.tab[aria-current="page"]::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 34px;
  height: 3px;
  border-radius: 3px;
  background: var(--brand);
}

.tab .tab-emoji {
  font-size: 20px;
  line-height: 1.2;
}

.tab .nav-badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 30px);
  min-width: 24px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  line-height: 22px;
  text-align: center;
}

.tab .nav-badge[data-empty="1"] {
  display: none;
}

/* --------------------------------------------------------------------------
   通知中心 / 设置
   -------------------------------------------------------------------------- */

.page-head {
  margin: 6px 2px 14px;
}

.page-head h1 {
  font-size: 20px;
  font-weight: 800;
  line-height: 1.4;
}

.page-head p {
  font-size: 16px;
  color: var(--text-dim);
  line-height: 1.6;
  margin-top: 2px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  padding: 16px;
  margin-bottom: 12px;
}

.card h2 {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 8px;
}

.card h3 {
  font-size: 17px;
  font-weight: 800;
  margin-bottom: 6px;
}

.card p,
.card li {
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-dim);
}

.card .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 16px;
  flex-wrap: wrap;
}

.card .row:last-child {
  border-bottom: 0;
}

.card .row .k {
  color: var(--text-dim);
  font-weight: 600;
}

.card .row .v {
  font-variant-numeric: tabular-nums;
  word-break: break-all;
  text-align: right;
}

.card .btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.card .btn-row button {
  min-height: var(--tap);
  padding: 8px 16px;
  font-weight: 700;
}

.card--danger {
  border-color: color-mix(in srgb, var(--danger) 40%, var(--border));
}

.rule-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 16px;
}

.rule-item:last-child {
  border-bottom: 0;
}

.rule-name {
  font-weight: 700;
}

.rule-meta {
  color: var(--text-faint);
}

.device-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.device-item:last-child {
  border-bottom: 0;
}

.device-info {
  flex: 1 1 auto;
  min-width: 0;
}

.device-name {
  font-weight: 700;
  font-size: 16px;
  word-break: break-word;
}

.device-meta {
  font-size: 16px;
  color: var(--text-faint);
}

.device-item button {
  flex: 0 0 auto;
  padding: 8px 14px;
  font-weight: 700;
}

.inbox-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.inbox-item {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-1);
  padding: 12px 14px;
  position: relative;
}

.inbox-item[data-unread="1"] {
  border-left: 5px solid var(--brand);
  background: color-mix(in srgb, var(--brand-soft) 40%, var(--surface));
}

.inbox-item .inbox-title {
  font-size: 17px;
  font-weight: 800;
  line-height: 1.6;
  word-break: break-word;
}

.inbox-item .inbox-body {
  font-size: 16px;
  color: var(--text-dim);
  line-height: 1.6;
  word-break: break-word;
}

.inbox-item .inbox-time {
  font-size: 16px;
  color: var(--text-faint);
  margin-top: 2px;
}

/* --------------------------------------------------------------------------
   Toast / 弹窗
   -------------------------------------------------------------------------- */

.toast-root {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--safe-bottom) + 84px);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  padding: 0 16px;
}

.toast {
  max-width: 480px;
  width: fit-content;
  padding: 12px 18px;
  border-radius: 999px;
  background: #11182a;
  color: #f8fafc;
  font-size: 16px;
  line-height: 1.6;
  box-shadow: var(--shadow-2);
  animation: toast-in 0.18s ease-out;
  word-break: break-word;
}

.toast[data-kind="error"] {
  background: #7f1d1d;
  color: #fee2e2;
}

.toast[data-kind="ok"] {
  background: #064e3b;
  color: #d1fae5;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 70;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 9, 18, 0.62);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.modal {
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  border: 1px solid var(--border);
  border-bottom: 0;
  box-shadow: var(--shadow-2);
  padding: 20px calc(18px + var(--safe-right))
    calc(18px + var(--safe-bottom)) calc(18px + var(--safe-left));
  animation: sheet-in 0.2s ease-out;
}

@keyframes sheet-in {
  from {
    transform: translateY(24px);
    opacity: 0.4;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal h2 {
  font-size: 19px;
  font-weight: 800;
  line-height: 1.4;
  margin-bottom: 8px;
}

.modal p {
  font-size: 16px;
  color: var(--text-dim);
  line-height: 1.6;
  white-space: pre-wrap;
}

.modal .modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}

.modal .modal-actions button {
  min-height: 52px;
  font-size: 17px;
  font-weight: 700;
}

/* --------------------------------------------------------------------------
   工具类
   -------------------------------------------------------------------------- */

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

[hidden] {
  display: none !important;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 16px;
}

.muted {
  color: var(--text-faint);
}

/* 远程窗口 */
.win-pick {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.win-pick button {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  height: auto;
  min-height: 44px;
  width: 100%;
  max-width: 100%;
  padding: 8px 10px;
  text-align: left;
  overflow: hidden;
}

.win-pick-name {
  font-size: 16px;
  font-weight: 600;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.win-pick-title {
  font-size: 13px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-faint);
}

.win-scale button {
  min-width: 64px;
}

.win-shot {
  margin: 12px 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-sunken, #e8edf7);
}

.win-shot img {
  display: block;
  width: 100%;
  height: auto;
}

.win-text {
  width: 100%;
  min-height: 84px;
  margin: 8px 0 12px;
  resize: vertical;
  font-size: 16px;
  line-height: 1.6;
}

[data-win-status][data-kind="ok"] {
  color: var(--ok, #128f5e);
}

[data-win-status][data-kind="error"] {
  color: var(--danger, #d93b3b);
}

/* 小屏微调：保证 >=16px 与 44px 触控不变 */
@media (max-width: 360px) {
  .stats {
    gap: 10px;
  }
  .stat {
    padding: 12px;
  }
  .action-grid {
    grid-template-columns: 1fr;
  }
  .composer-row {
    gap: 6px;
  }
  .btn-send {
    min-width: 68px;
  }
}

/* 横屏 / 平板：内容居中，不复制桌面布局 */
@media (min-width: 721px) {
  #main {
    padding-left: 20px;
    padding-right: 20px;
  }
}

/* 减少动效偏好 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
