/* ============================================================
 * 重置 / 中文排版 / iOS 安全区 / 基础件（按钮 · 卡片 · 输入）
 * ============================================================ */

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

html { height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  /* 100vh 含 iOS 地址栏；16.4+ 用 dvh，老版本回退 */
  min-height: 100dvh;
  background: var(--surface-page);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC",
    "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color-scheme: light;
  -webkit-font-smoothing: antialiased;
}

#view {
  min-height: calc(100vh - var(--tabbar-h));
  min-height: calc(100dvh - var(--tabbar-h));
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}

.hidden { display: none !important; }

/* ---- 顶栏 ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 8px 0 8px;
  background: var(--surface-card);
  border-bottom: 1px solid var(--divider);
}
.topbar-title {
  flex: 1;
  min-width: 0;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-sub {
  flex-shrink: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--text-sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-btn {
  flex-shrink: 0;
  border: 0;
  background: none;
  padding: 8px;
  font-size: 14px;
  color: var(--brand);
  cursor: pointer;
  border-radius: 8px;
}
.topbar-btn:active { background: var(--brand-bg); }
.topbar-btn.danger { color: var(--wrong); }

/* ---- 卡片 ---- */
.card {
  background: var(--surface-card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  margin: 12px var(--pad-page);
  padding: 14px;
}

.section-title {
  margin: 18px var(--pad-page) 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-sub);
}

/* ---- 按钮 ---- */
.btn {
  display: block;
  width: 100%;
  border: 0;
  border-radius: var(--radius-btn);
  padding: 13px 16px;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:active { background: var(--brand-dark); }
.btn-outline {
  background: var(--surface-card);
  color: var(--brand);
  border: 1px solid var(--brand);
}
.btn-outline:active { background: var(--brand-bg); }
.btn-danger-outline {
  background: var(--surface-card);
  color: var(--wrong);
  border: 1px solid var(--wrong);
}
.btn-sm {
  width: auto;
  display: inline-block;
  padding: 8px 14px;
  font-size: 14px;
}

/* ---- 输入：iOS 聚焦自动放大，一律 16px ---- */
input[type="text"], input[type="search"], textarea, select {
  width: 100%;
  font-size: 16px;
  font-family: inherit;
  color: var(--text-main);
  background: var(--surface-card);
  border: 1px solid var(--divider);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
input:focus, textarea:focus { border-color: var(--brand); }
textarea { resize: vertical; min-height: 72px; }

/* ---- 通用行 ---- */
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  background: var(--surface-card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  margin: 10px var(--pad-page);
  cursor: pointer;
  border: 0;
  width: calc(100% - 2 * var(--pad-page));
  text-align: left;
  font-size: 15px;
  color: var(--text-main);
  font-family: inherit;
}
.row:active { background: #F7F8FC; }
.row-main { flex: 1; min-width: 0; }
.row-title {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-sub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-arrow { flex-shrink: 0; color: var(--text-hint); font-size: 16px; }
.row-badge {
  flex-shrink: 0;
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-size: 12px;
  text-align: center;
}
.row-ico {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--brand-bg);
  color: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

/* ---- 标签 ---- */
.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.6;
  background: var(--brand-bg);
  color: var(--brand);
}
.tag-gray { background: #EEF0F4; color: var(--text-sub); }
.tag-green { background: var(--opt-ok-bg); color: var(--opt-ok-text); }
.tag-red { background: var(--opt-bad-bg); color: var(--opt-bad-text); }

/* ---- 空态 ---- */
.empty {
  margin: 40px var(--pad-page);
  text-align: center;
  color: var(--text-sub);
  font-size: 14px;
}

/* ---- 底部导航：sticky 在滚动容器内，避免 iOS fixed 抖动 ---- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface-card);
  border-top: 1px solid var(--divider);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  background: none;
  color: var(--text-sub);
  font-size: 11px;
  cursor: pointer;
  padding: 0;
}
.tab.active { color: var(--brand); }
.tab-ico { display: flex; }

/* ---- 底部抽屉 / 弹层 ---- */
.sheet-mask {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 80vh;
  max-height: 80dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface-card);
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
}
.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--divider);
  margin: 0 auto 12px;
}
.sheet-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  text-align: center;
}
.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}
.sheet-actions .btn { flex: 1; }

/* ---- Toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  max-width: 78vw;
  padding: 9px 16px;
  border-radius: 10px;
  background: rgba(17, 24, 39, 0.88);
  color: #fff;
  font-size: 14px;
  text-align: center;
  pointer-events: none;
  animation: toast-in 0.18s ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 6px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---- 进度条 ---- */
.progress {
  height: 6px;
  border-radius: 3px;
  background: var(--divider);
  overflow: hidden;
}
.progress > div {
  height: 100%;
  border-radius: 3px;
  background: var(--brand);
  transition: width 0.2s;
}
