/* 手机优先样式 —— 单列布局，触控目标够大 */
:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --fg: #1f2328;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #2563eb;
  --ok: #15803d;
  --warn: #b45309;
  --err: #b91c1c;
  --radius: 12px;
}

* { box-sizing: border-box; }

/* ⚠️ 必须有这一条：下面给 .banner 设了 display:flex，
   而 CSS 的 display 会盖掉 hidden 属性自带的 display:none —— 不加这句，
   那些「隐藏」的提示条会一直显示在页面上。 */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC",
        "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--brand);
  color: #fff;
  padding: 20px 16px calc(20px + env(safe-area-inset-top, 0px));
}
.brand-logo {
  flex: none;
  display: block;
  width: 32px;
  height: 32px;
  border-radius: 8px;
}
.brand-text { flex: 1; min-width: 0; }
.topbar h1 { margin: 0; font-size: 20px; }
.topbar .sub { margin: 4px 0 0; font-size: 13px; opacity: .85; }

/* 顶栏里的链接（管理员才看得到的「后台」入口） */
.topbar-link {
  flex: none;
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 14px;
  font-size: 14px;
  color: #fff;
  text-decoration: none;
  background: rgba(255, 255, 255, .18);
  border-radius: 999px;
}
.topbar-link:active { background: rgba(255, 255, 255, .3); }

/* 顶栏右侧的退出按钮 —— 需要盖掉全局 button 的 100% 宽与上边距 */
.logout-btn {
  flex: none;
  width: auto;
  margin: 0;
  padding: 8px 16px;
  min-height: 40px;
  font-size: 14px;
  background: rgba(255, 255, 255, .18);
  border-radius: 999px;
}
.logout-btn:active { background: rgba(255, 255, 255, .3); }

main {
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  max-width: 640px;
  margin: 0 auto;
}

/* 顶部 Tab 切换 —— 一次只显示一个面板，页面不会被记录列表越拉越长 */
.tabs {
  display: flex;
  gap: 6px;
  padding: 4px;
  margin-bottom: 12px;
  background: #e6e9ee;
  border-radius: 999px;
}
/* ⚠️ 需要盖掉全局 button 的 100% 宽与上边距 */
.tab {
  flex: 1;
  width: auto;
  margin: 0;
  min-height: 44px;          /* 触控目标 */
  padding: 10px 12px;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border-radius: 999px;
}
.tab:active { opacity: .7; }
.tab.is-active {
  color: var(--brand);
  background: var(--card);
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.tab .count { margin-left: 2px; }
.tab.is-active .count { color: var(--brand); background: #eff6ff; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.card h2 { margin: 0 0 12px; font-size: 16px; }

/* 卡片标题行：标题 + 右侧的「取消编辑」 */
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.card-head h2 { margin: 0; }

/* 文字按钮：需要盖掉全局 button 的 100% 宽与上边距 */
.link-btn {
  flex: none;
  width: auto;
  margin: 0;
  padding: 6px 10px;
  min-height: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--brand);
  background: transparent;
  border-radius: 8px;
}
.link-btn:active { background: var(--bg); }

/* 受试者信息与临床数据之间留一道呼吸 —— 它们之间隔着一个 </form> 边界 */
#record-form { margin-top: 16px; }

/* 提示条（草稿恢复 / 首次使用提醒） */
.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 12px;
  padding: 12px 14px;
  margin-bottom: 16px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
}
.banner-text { margin: 0; font-size: 14px; color: #1e3a8a; }
.banner-actions { display: flex; gap: 8px; }
.banner-btn {
  width: auto;
  margin: 0;
  padding: 8px 16px;
  min-height: 40px;
  font-size: 14px;
  font-weight: 500;
  color: var(--brand);
  background: #fff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
}
.banner-btn--primary {
  color: #fff;
  background: var(--brand);
  border-color: var(--brand);
}

label {
  display: block;
  margin: 14px 0 6px;
  font-size: 14px;
  font-weight: 600;
}
label:first-of-type { margin-top: 0; }

input, select, textarea {
  width: 100%;
  padding: 12px;
  font-size: 16px;          /* ≥16px 可避免 iOS 自动放大 */
  font-family: inherit;
  color: inherit;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  min-height: 48px;         /* 触控目标 ≥44px */
  appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236b7280' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 38px;
}
textarea { min-height: 72px; resize: vertical; }

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
  border-color: var(--brand);
}

/* 后端打回时高亮出错的那个输入框，让用户一眼看到问题在哪 */
.field-error {
  border-color: var(--err);
  background: #fef2f2;
}
.field-error:focus {
  outline-color: var(--err);
  border-color: var(--err);
}

button {
  width: 100%;
  margin-top: 20px;
  padding: 15px;
  font-size: 17px;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: var(--brand);
  border: 0;
  border-radius: 10px;
  min-height: 52px;
  cursor: pointer;
}
button:active { opacity: .85; }
button:disabled { background: #9ca3af; cursor: default; }

/* 提示现在位于两个 Tab 面板**之外**（提交成功后会切到列表，提示仍要可见），
   所以用 margin-bottom 而不是原来的 margin-top。空的时候整条不占位。 */
.msg { margin: 0 0 12px; font-size: 14px; min-height: 0; }
.msg:empty { display: none; }
.msg.ok  { color: var(--ok); }
.msg.err { color: var(--err); }

.count {
  display: inline-block;
  min-width: 22px;
  padding: 1px 8px;
  font-size: 13px;
  color: var(--muted);
  background: var(--bg);
  border-radius: 999px;
}

.records { list-style: none; margin: 0; padding: 0; }
/* 列表项可点击 → 载入到上方表单编辑 */
.records li {
  padding: 12px 0;
  border-top: 1px solid var(--line);
  cursor: pointer;
  min-height: 44px;          /* 触控目标 */
}
.records li:first-child { border-top: 0; }
.records li:active { background: var(--bg); }
.records li:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 6px;
}
.rec-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.rec-body { margin-top: 4px; font-size: 13px; color: var(--muted); }

.tag {
  padding: 2px 8px;
  font-size: 12px;
  border-radius: 999px;
  white-space: nowrap;
}
.tag-success { color: var(--ok);   background: #dcfce7; }
.tag-failure { color: var(--err);  background: #fee2e2; }
.tag-lost    { color: var(--warn); background: #fef3c7; }

.empty { margin: 0; color: var(--muted); font-size: 14px; }
