/*
 * sd-buddy 样式。
 *
 * 基调对齐原站（sd.52cf.cn）：#efeef1 页面底色、白色圆角块、#007aff 主色。
 * 不引 CSS 框架 —— 托管环境不能跑 npm，少一个外部请求也少一个失败点。
 */

:root {
  --bg: #efeef1;
  --card: #ffffff;
  --text: #3e4449;
  --text-dim: #888;
  --primary: #007aff;
  --primary-dark: #0067d8;
  --ok: #33ad6e;
  --warn: #b8860b;
  --err: #d93f3f;
  --border: #e6e3e6;
  --radius: 16px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/*
 * 登录层 = 蒙版（overlay）。
 *
 * ## 为什么是蒙版而不是「两个页面」
 *
 * 原来的做法是 showAuth / showApp 用 display 切换两块内容 —— 那本质上是
 * 「两个页面互换」，浏览器不重置滚动，于是长页面从中间展开，看着像往下滑。
 *
 * 蒙版语义则简单得多：主界面**一直在那里**（可以正常滚动、正常渲染），
 * 登录层盖在上面；登录成功后把蒙版掀掉，主界面本来就处于正确状态，
 * 不需要任何位置纠正 —— 因为底下那层从头到尾没动过。
 *
 * 这也更符合产品直觉：用户看到的是「一个被锁住的应用」，而不是「一个登录页」。
 */
body.auth-locked {
  /* 蒙版期间锁住底层滚动：否则背景会跟着手指滑，露出底下的长短不齐 */
  overflow: hidden;
  /* iOS 上 overflow:hidden 有时不彻底，touch-action 再压一道 */
  touch-action: none;
}

/* 蒙版期间主界面不可交互（点击/聚焦全部挡住），但仍照常渲染 */
body.auth-locked #appWrap {
  pointer-events: none;
  user-select: none;
}


.page {
  width: 92%;
  max-width: 700px;
  margin: 0 auto;
  padding: 20px 0 64px;
}

/* ---------------- 顶部 ---------------- */

.hero {
  text-align: center;
  padding: 28px 16px 22px;
}

.hero-title {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text);
}

.hero-sub {
  margin-top: 6px;
  font-size: 14px;
  color: var(--text-dim);
  letter-spacing: 1px;
}

.hero-count {
  margin-top: 16px;
  font-size: 14px;
  color: var(--text-dim);
}

.count-num {
  color: var(--primary);
  font-weight: 700;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

/* ---------------- 卡片块 ---------------- */

.block {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 20px 20px;
  margin-bottom: 15px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.block-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 14px;
  font-size: 17px;
  font-weight: 600;
}

.block-title-extra {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 400;
  color: var(--text-dim);
}

/* ---------------- 表单 ---------------- */

.field {
  margin-bottom: 13px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  color: var(--text-dim);
}

.label-note {
  font-size: 12px;
  color: #bbb;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="time"],
select {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  font-size: 16px;
  /* 16px 是 iOS 不自动放大的下限，别改小 */
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12);
}

input::placeholder { color: #bbb; }

/* 去掉 number 的上下小箭头，手机上没用还占位 */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* ---------------- 按钮 ---------------- */

.btn-primary {
  display: block;
  width: 100%;
  height: 48px;
  margin-top: 16px;
  border: none;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.08s;
}

.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: scale(0.985); }
.btn-primary:disabled { background: #b8b8bd; cursor: default; }

.btn-mini {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.btn-mini:hover { background: #f5f5f5; }
.btn-mini:disabled { color: #bbb; cursor: default; }
.btn-mini.primary { border-color: var(--primary); color: var(--primary); }
.btn-mini.danger { border-color: #f0c4c4; color: var(--err); }

/* ---------------- 标签页 ---------------- */

.tabs {
  display: flex;
  gap: 8px;
  padding: 4px;
  background: #f3f0f0;
  border-radius: 12px;
  margin-bottom: 16px;
}

.tab {
  flex: 1;
  height: 38px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
}

.tab.active {
  background: #fff;
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.tab-panel.hidden { display: none; }

.cap-preview {
  margin-top: 10px;
  padding: 10px 12px;
  background: #fff8dc;
  border-radius: 10px;
  font-size: 13px;
  color: var(--warn);
}

.cap-preview:empty { display: none; }

/* ── 随机步数：开关 + 区间行（2026-11-21）─────────────────────────
 *
 * 开关用「真 checkbox + 视觉层」的做法，而不是 div + JS 切类：
 * 前者自带键盘可聚焦、可空格切换、屏幕阅读器能识别，也避免上一轮
 * 「classList.add 了但 CSS 里没这条规则 → 静默失效」那类问题。
 * checkbox 用 opacity:0 覆盖在开关上，点击区域与视觉完全重合。
 */
.switch-row {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 0 !important;
  cursor: pointer;
  position: relative;
  padding: 4px 0;
}
.switch-input {
  position: absolute;
  right: 0;
  width: 52px;
  height: 30px;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}
.switch-ui {
  flex: 0 0 auto;
  width: 52px;
  height: 30px;
  border-radius: 15px;
  background: #d6d6d6;
  position: relative;
  transition: background 0.18s ease;
}
.switch-ui::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.18s ease;
}
/* 选中态：用 :checked + 兄弟选择器驱动，纯 CSS，不依赖 JS */
.switch-input:checked + .switch-ui {
  background: var(--accent, #07c160);
}
.switch-input:checked + .switch-ui::after {
  transform: translateX(22px);
}
.switch-input:focus-visible + .switch-ui {
  outline: 2px solid var(--accent, #07c160);
  outline-offset: 2px;
}

/* 区间两个输入框并排。min-width:0 是关键 —— 缺了 flex 子项不会收缩，
 * 在窄屏上会把右边那个挤出容器，看起来像「没有最大值输入框」。 */
.range-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.range-row > input {
  flex: 1 1 0;
  min-width: 0;
}
.range-sep {
  flex: 0 0 auto;
  color: var(--text-dim);
  font-size: 14px;
}

.hint {
  margin: 10px 0 0;
  font-size: 12px;
  line-height: 1.6;
  color: #999;
}

/* ---------------- 任务列表 ---------------- */

.task-list { display: flex; flex-direction: column; gap: 10px; }

.empty {
  padding: 24px 0;
  text-align: center;
  font-size: 14px;
  color: #bbb;
}

.task-card {
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 13px 14px;
  background: #fff;
  transition: opacity 0.2s;
}

.task-card.off { opacity: 0.55; }

.task-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.task-name {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.task-badge {
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 500;
}

.task-badge.daily { background: #e6f0ff; color: var(--primary); }
.task-badge.hourly { background: #e6f9ee; color: var(--ok); }

.task-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.task-meta {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-dim);
}

.task-status {
  margin-top: 5px;
  font-size: 13px;
  color: #666;
  word-break: break-all;
}

.task-next {
  margin-top: 5px;
  font-size: 12px;
  color: var(--primary);
}

/* ---------------- 日志 ---------------- */

.log-viewport {
  /*
   * 必须固定高度：scrollHeight === clientHeight 时弹簧不会被启动，
   * 看上去就像“丝滑滚动失效”。高度取 42vh 是为了在手机上同时
   * 看得到任务列表和日志（日志太矮就失去意义）。
   */
  height: 42vh;
  min-height: 180px;
  max-height: 420px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 12px;
  border-radius: 12px;
  background: #1b1c1f;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.65;
  /* 让 iOS 上的滚动不反弹到外层 */
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.log-line {
  display: flex;
  gap: 8px;
  white-space: pre-wrap;
  word-break: break-all;
  color: #c8ccd4;
}

.log-time {
  flex: 0 0 auto;
  color: #6b7280;
  font-variant-numeric: tabular-nums;
}

.log-text { flex: 1 1 auto; }

.log-line.ok .log-text { color: #6ee7a8; }
.log-line.warn .log-text { color: #fbd38d; }
.log-line.error .log-text { color: #fca5a5; }
.log-line.info .log-text { color: #c8ccd4; }

.log-status {
  margin-top: 8px;
  font-size: 12px;
  color: #aaa;
}

.follow-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}

/* ---------------- 页脚 / 浮层 ---------------- */

.foot {
  margin-top: 22px;
  text-align: center;
  font-size: 12px;
  color: #b0b0b6;
}

.foot .dot { margin: 0 6px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translate(-50%, 20px);
  max-width: 84vw;
  padding: 11px 18px;
  border-radius: 12px;
  background: rgba(30, 32, 36, 0.94);
  color: #fff;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s, transform 0.22s;
  z-index: 99;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.bad { background: rgba(180, 40, 40, 0.95); }

/* ---------------- 窄屏微调 ---------------- */

@media (max-width: 380px) {
  .page { width: 94%; }
  .block { padding: 16px 15px 18px; }
  .hero-title { font-size: 26px; }
  .task-actions { width: 100%; }
}

/* ================= 登录 / 注册 ================= */

.auth-wrap {
  /* 铺满视口，盖在主界面之上 */
  position: fixed;
  inset: 0;
  z-index: 100;

  /* 半透明玻璃质感的遮罩：底下的主界面隐约可见，说明「应用还在那儿，只是被锁住了」 */
  background: rgba(239, 238, 241, 0.86);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  backdrop-filter: blur(14px) saturate(1.2);

  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  /* 矮屏（横屏/小窗）时蒙版自己滚，否则按钮会被切掉 */
  overflow-y: auto;
  overscroll-behavior: contain;

  /* 掀蒙版时的收尾动画：先淡出再移除，避免「啪」一下消失 */
  animation: mask-in 0.22s ease-out;
}

/* 蒙版退场：由 JS 加 .mask-out 触发，动画结束后才真正 display:none */
.auth-wrap.mask-out {
  animation: mask-out 0.2s ease-in forwards;
  pointer-events: none;
}

/*
 * 蒙版彻底移除。
 *
 * 【必须显式写】JS 里 mask.classList.add('hidden') 一直在执行，
 * 但上一版 CSS 只有 .page.hidden / .auth-form.hidden / .tab-panel.hidden，
 * **没有 .auth-wrap.hidden** —— 于是那个 class 是个空操作，蒙版永远不消失，
 * 表现出来就是“登录后没有跳转”（登录层仍然铺满 100vh）。
 *
 * 教训：给元素加 class 必须确认该类在 CSS 里真的有规则，否则静默失效。
 */
.auth-wrap.hidden {
  display: none !important;
}

/* 兜底：任何带 .hidden 的元素都应该消失。以前只写了点前缀类，漏了裸类。 */
.hidden {
  display: none !important;
}

@keyframes mask-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes mask-out {
  from { opacity: 1; }
  to   { opacity: 0; }
}

/* 登录卡片在蒙版上浮起一点，不要与背景糊在一起 */
.auth-wrap .auth-card {
  box-shadow: 0 12px 44px rgba(0, 0, 0, 0.14);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: 20px;
  padding: 30px 24px 24px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
}

.auth-logo {
  text-align: center;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 2px;
}

.auth-sub {
  margin-top: 4px;
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
}

.auth-tabs {
  display: flex;
  gap: 8px;
  margin: 22px 0 18px;
  padding: 4px;
  background: #f3f0f0;
  border-radius: 12px;
}

.auth-tab {
  flex: 1;
  height: 38px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
}

.auth-tab.active {
  background: #fff;
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.auth-form.hidden { display: none; }

.auth-note {
  margin: 16px 0 0;
  font-size: 12px;
  line-height: 1.6;
  color: #aaa;
  text-align: center;
}

.page.hidden { display: none; }

/* ================= 顶部用户栏 ================= */

.hero-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
}

.hero-user {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hero-user .who {
  font-size: 13px;
  color: var(--text-dim);
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ================= 刷步账号 ================= */

.acc-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.acc-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fafafa;
}

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

.acc-name {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.acc-note {
  margin-top: 2px;
  font-size: 12px;
  color: var(--primary);
}

.acc-meta {
  margin-top: 2px;
  font-size: 11.5px;
  color: #aaa;
}

.add-acc {
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}

.field-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.field-row > input { flex: 1 1 0; min-width: 0; }
.field-row > button { flex: 0 0 auto; height: 46px; }

.btn-secondary {
  padding: 0 16px;
  border: 1px solid var(--primary);
  border-radius: 12px;
  background: #fff;
  color: var(--primary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.btn-secondary:hover { background: #f0f6ff; }
.btn-secondary:disabled { border-color: #ccc; color: #bbb; cursor: default; }
