:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --label: #1c1c1e;
  --secondary: #8e8e93;
  --sep: rgba(60, 60, 67, 0.12);
  --blue: #007aff;
  --green: #34c759;
  --orange: #ff9500;
  --red: #ff3b30;
  --radius: 14px;
  --bar-bg: rgba(249, 249, 249, 0.82);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --label: #ffffff;
    --secondary: #98989d;
    --sep: rgba(84, 84, 88, 0.55);
    --bar-bg: rgba(22, 22, 24, 0.86);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.42;
  color: var(--label);
  background: var(--bg);
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}

/* ---------------- 顶栏 ---------------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bar-bg);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--sep);
  padding-top: env(safe-area-inset-top);
}
.appbar-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 10px 16px 10px;
}
/* 顶栏：标题居中，返回按钮固定左侧，账户选择器固定右侧 */
.title-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  gap: 10px;
}
.title-row h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
  text-align: center;
  max-width: 56%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-back {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  gap: 1px;
  border: none;
  background: transparent;
  color: var(--blue, #007aff);
  font-size: 16px;
  font-weight: 500;
  padding: 4px 6px 4px 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.nav-back svg { width: 19px; height: 19px; display: block; }
.nav-back[hidden] { display: none; }
.page-sub {
  margin: 3px 0 0;
  text-align: center;
  font-size: 12px;
  color: var(--secondary, #8e8e93);
  letter-spacing: -0.1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.page-sub[hidden] { display: none; }
.tabbar.hide { display: none; }
.account-picker {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  appearance: none;
  -webkit-appearance: none;
  border: none;
  background: rgba(118, 118, 128, 0.12);
  color: var(--label);
  font-size: 13px;
  font-weight: 500;
  padding: 7px 26px 7px 11px;
  border-radius: 100px;
  max-width: 42vw;
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5L6 8l3.5-3.5' fill='none' stroke='%238e8e93' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  background-size: 12px;
}

/* ---------------- 内容 ---------------- */
.view { max-width: 720px; margin: 0 auto; padding: 16px 16px 24px; }

.group-title {
  font-size: 13px;
  color: var(--secondary);
  padding: 18px 4px 7px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.group-title:first-child { padding-top: 0; }

.group {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  position: relative;
  min-height: 52px;
}
.row + .row::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  height: 0.5px;
  background: var(--sep);
}
.row-main { flex: 1; min-width: 0; }
.row-title {
  font-size: 16px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-sub {
  font-size: 13px;
  color: var(--secondary);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-actions { display: flex; gap: 8px; flex-shrink: 0; }

.empty {
  text-align: center;
  color: var(--secondary);
  font-size: 14px;
  padding: 40px 20px;
}

.footer-note {
  font-size: 12.5px;
  color: var(--secondary);
  padding: 10px 4px 0;
  line-height: 1.5;
}

/* ---------------- 控件 ---------------- */
.btn {
  border: none;
  background: rgba(118, 118, 128, 0.12);
  color: var(--label);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 100px;
  cursor: pointer;
  font-family: inherit;
}
.btn:active { opacity: 0.6; }
.btn.primary { background: var(--blue); color: #fff; }
.btn.danger { background: rgba(255, 59, 48, 0.12); color: var(--red); }
.btn.ghost { background: transparent; color: var(--blue); padding: 8px 6px; }
.btn.block { width: 100%; padding: 14px; border-radius: 12px; font-size: 16px; font-weight: 600; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

.add-fab {
  position: fixed;
  right: max(18px, calc(50vw - 360px + 18px));
  bottom: calc(86px + env(safe-area-inset-bottom));
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  border: none;
  box-shadow: 0 6px 20px rgba(0, 122, 255, 0.38);
  cursor: pointer;
  z-index: 20;
}
.add-fab:active { transform: scale(0.94); }

/* ---------------- 底部标签栏 ---------------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  background: var(--bar-bg);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--sep);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  border: none;
  background: none;
  color: var(--secondary);
  font-family: inherit;
  font-size: 10.5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 2px 7px;
  cursor: pointer;
}
.tab svg { width: 25px; height: 25px; }
.tab.active { color: var(--blue); }

/* ---------------- 底部弹层表单 ---------------- */
.sheet-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.36);
  z-index: 60;
  display: flex;
  align-items: flex-end;
  animation: fade 0.18s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes slide { from { transform: translateY(100%) } to { transform: translateY(0) } }

.sheet {
  width: 100%;
  max-height: 88vh;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  animation: slide 0.26s cubic-bezier(0.32, 0.72, 0, 1);
  padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 640px) {
  .sheet { max-width: 560px; margin: 0 auto; border-radius: 18px; margin-bottom: 24px; }
  .sheet-mask { align-items: center; }
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 0.5px solid var(--sep);
}
.sheet-head strong { font-size: 16px; font-weight: 600; }
.sheet-head button {
  border: none;
  background: none;
  font-family: inherit;
  font-size: 16px;
  color: var(--blue);
  cursor: pointer;
  padding: 4px 0;
}
.sheet-head button.ok { font-weight: 600; }
.sheet-body { overflow: auto; padding: 16px; -webkit-overflow-scrolling: touch; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 13px;
  color: var(--secondary);
  margin-bottom: 6px;
  padding-left: 2px;
}
/* 关键：<input> 未显式写 type 时默认就是 text，用 input[type="text"] 匹配不到，
   会导致输入框退回浏览器原生样式（细边框 + 系统字体），与 textarea / select 的卡片风格不协调。
   这里改用排除式选择器，让所有单行输入框统一走同一套样式。 */
.field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
.field select,
.field textarea {
  width: 100%;
  border: none;
  background: var(--card);
  color: var(--label);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.35;
  padding: 12px 14px;
  border-radius: 11px;
  outline: none;
  min-height: 44px;
}
.field textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.field input:focus, .field select:focus, .field textarea:focus {
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.22);
}
.field input::placeholder, .field textarea::placeholder { color: var(--secondary); opacity: 0.75; }

/* 文件选择框：默认控件在各浏览器里长得完全不一样，统一压成胶囊按钮 */
.field input[type="file"] {
  width: 100%;
  font-family: inherit;
  font-size: 13px;
  color: var(--secondary);
  background: var(--card);
  border-radius: 11px;
  padding: 9px 12px;
  cursor: pointer;
}
.field input[type="file"]::file-selector-button {
  border: none;
  background: rgba(0, 122, 255, 0.12);
  color: var(--blue);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 7px 13px;
  border-radius: 100px;
  margin-right: 10px;
  cursor: pointer;
}
.field .hint { font-size: 12px; color: var(--secondary); margin-top: 6px; padding-left: 2px; line-height: 1.45; }

.checks { display: flex; flex-wrap: wrap; gap: 8px; }
/* 设备勾选区顶部工具条：全选按钮 + 已选计数 */
.checks-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.checks-head .hint { margin: 0; }
.checks-head .btn { padding: 5px 10px; }
.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--card);
  padding: 9px 12px;
  border-radius: 100px;
  font-size: 13.5px;
  cursor: pointer;
}
.check input { accent-color: var(--blue); }
.check.on { box-shadow: inset 0 0 0 1.5px var(--blue); color: var(--blue); }
/* 证书选择项：两行结构（名称 + 来源标识/创建时间），便于区分本机创建与 Apple 端已有 */
.check.col { display: flex; align-items: flex-start; border-radius: 12px; padding: 10px 12px; flex: 1 1 100%; max-width: 100%; }
.check.col.on { color: var(--label); }
.check.col > .check-body { display: block; flex: 1 1 auto; min-width: 0; }
.check.col > .check-body > .check-title { display: block; font-size: 13.5px; font-weight: 500; line-height: 1.35; }
.check.col > .check-body > .check-meta { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.check.col .check-time { font-size: 11.5px; color: var(--secondary); }

/* ---------------- 提示 ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  background: rgba(28, 28, 30, 0.92);
  color: #fff;
  font-size: 14px;
  padding: 11px 18px;
  border-radius: 100px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.22s ease;
  z-index: 90;
  max-width: 82vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: rgba(255, 59, 48, 0.95); }

.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 100px;
  background: rgba(0, 122, 255, 0.12);
  color: var(--blue);
  white-space: nowrap;
}
.badge.green { background: rgba(52, 199, 89, 0.14); color: var(--green); }
.badge.gray { background: rgba(142, 142, 147, 0.16); color: var(--secondary); }
.badge.red { background: rgba(255, 59, 48, 0.14); color: var(--red); }

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.7s linear infinite;
  vertical-align: -3px;
}
@keyframes spin { to { transform: rotate(360deg) } }

/* ---------------- 模块入口 / 资产页 ---------------- */
.modules {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.mod {
  text-align: left;
  border: none;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  font-family: inherit;
  color: var(--label);
}
.mod:active { opacity: 0.62; }
.mod-name { font-size: 15px; font-weight: 600; }
.mod-desc { font-size: 12px; color: var(--secondary); margin-top: 3px; line-height: 1.35; }
.mod-count { font-size: 12px; color: var(--blue); margin-top: 6px; }

.back { padding-left: 0; margin: -4px 0 10px; display: inline-flex; align-items: center; gap: 4px; }

.btn.sm { padding: 6px 11px; font-size: 13px; }

/* 设备余额：账户卡片内的胶囊数值 */
.balance { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.balance span {
  font-size: 12px;
  color: var(--secondary);
  background: rgba(118, 118, 128, 0.1);
  padding: 2px 9px;
  border-radius: 100px;
}
.balance span b { color: var(--label); font-weight: 600; }
.balance span.low b { color: var(--orange); }
.balance span.empty b { color: var(--red); }

/* 多按钮行：允许换行，避免在窄屏被挤压变形 */
.row-actions { flex-wrap: wrap; justify-content: flex-end; }
