/**
 * TDAIO 模块门户 — 样式
 * ============================================================
 * 视觉基调与《我的丝绸之路》完全一致（取自 uni.scss 的设计令牌）：
 *   - 系统字体栈（SF Pro → PingFang SC）
 *   - iOS systemGroupedBackground 灰底 + 纯白卡片
 *   - 大圆角、极淡发丝描边、克制阴影
 *   - 靠留白与字重建立层级，不靠边框和重色
 */

:root {
  /* ---- 文字层级（iOS label 体系） ---- */
  --ink:   #1d1d1f;
  --ink-2: #3a3a3c;
  --ink-3: #8e8e93;
  --ink-4: #c7c7cc;

  /* ---- 背景与分隔 ---- */
  --bg:     #f2f2f7;
  --bg-2:   #ffffff;
  --line:   rgba(60, 60, 67, 0.10);
  --line-2: rgba(60, 60, 67, 0.06);
  --fill:   rgba(120, 120, 128, 0.12);

  /* ---- TDAIO 品牌色 ---- */
  --accent:       #0a4d8c;
  --accent-soft:  #e7eff8;
  --accent-line:  #a9c6e2;
  --accent-press: #083f73;

  /* ---- iOS 系统色 ---- */
  --ok:     #34c759;
  --warn:   #ff9500;
  --danger: #ff3b30;

  /* ---- 圆角 ---- */
  --r-sm:   10px;
  --r-md:   14px;
  --r-lg:   20px;
  --r-pill: 999px;

  /* ---- 间距 ---- */
  --sp-1: 6px;
  --sp-2: 12px;
  --sp-3: 18px;
  --sp-4: 24px;
  --sp-5: 34px;
  --sp-6: 48px;

  /* ---- 触摸目标（无障碍下限 44px） ---- */
  --tap-min: 48px;

  /* ---- 阴影（iOS 极克制） ---- */
  --shadow-card:  0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-raise: 0 4px 16px rgba(0, 0, 0, 0.08);

  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display',
          'PingFang SC', 'Hiragino Sans GB', 'Helvetica Neue', 'Microsoft YaHei', sans-serif;
}

* { box-sizing: border-box; }

/**
 * ⚠️ 必须放在所有 display 规则之前并加 !important。
 * 浏览器默认的 [hidden]{display:none} 优先级极低，任何 `.foo{display:block}`
 * 都能压过它 —— 结果就是「设了 hidden 却照样显示」。
 * 本项目踩过两次：加载转圈浮在所有页面上、登录页多出「姓名/确认密码」两个字段。
 * 用一条 !important 规则根治，好过在每个组件上补一个 [hidden] 变体。
 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body { min-height: 100vh; display: flex; flex-direction: column; }

/* ============================================================
   顶栏
   ============================================================ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(242, 242, 247, 0.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line-2);
  padding-top: env(safe-area-inset-top);
}

.topbar-inner {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px var(--sp-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.brand-mark {
  width: 34px; height: 34px;
  flex: 0 0 auto;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand-text { min-width: 0; }
.brand-name { font-size: 15px; font-weight: 600; letter-spacing: 0.01em; }
.brand-sub {
  font-size: 12px; color: var(--ink-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---- 语言按钮（细线图标 + 固定英文 "Language"） ---- */
.lang-btn {
  display: inline-flex; align-items: center; gap: 6px;
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--bg-2);
  color: var(--ink-2);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.lang-btn:hover { background: #fafafa; }
.lang-btn:active { background: var(--fill); }
.lang-btn svg { width: 17px; height: 17px; }

.lang-menu {
  position: absolute;
  right: 16px;
  top: calc(100% - 4px);
  z-index: 30;
  margin: 0; padding: 6px;
  list-style: none;
  min-width: 150px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-raise);
}
.lang-menu li {
  padding: 11px 14px;
  border-radius: var(--r-sm);
  font-size: 15px;
  cursor: pointer;
}
.lang-menu li:hover { background: var(--bg); }
.lang-menu li[aria-selected="true"] { color: var(--accent); font-weight: 600; }

/* ============================================================
   主舞台
   ============================================================ */
.stage {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: var(--sp-5) var(--sp-4) calc(var(--sp-6) + env(safe-area-inset-bottom));
}

/* ---- 加载态 ---- */
#view-loading { display: flex; justify-content: center; padding-top: 30vh; }

.spinner {
  width: 26px; height: 26px;
  border: 2.5px solid var(--ink-4);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
}

/* ============================================================
   登录 / 注册
   ============================================================ */
.auth-card {
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  padding: var(--sp-5) var(--sp-4) var(--sp-4);
}

.auth-title {
  margin: 0 0 6px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.auth-sub {
  margin: 0 0 var(--sp-4);
  font-size: 15px;
  color: var(--ink-3);
}

.field { display: block; margin-bottom: var(--sp-3); }
.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-3);
  letter-spacing: 0.01em;
}

.field input {
  width: 100%;
  min-height: var(--tap-min);
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg);
  color: var(--ink);
  font-family: inherit;
  font-size: 17px; /* ≥16px 防止 iOS 聚焦时自动放大 */
  transition: border-color 0.15s ease, background 0.15s ease;
}
.field input:focus {
  outline: none;
  background: var(--bg-2);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field input::placeholder { color: var(--ink-4); }

.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 48px; }
.pw-toggle {
  position: absolute;
  right: 4px; top: 50%;
  transform: translateY(-50%);
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border: 0; background: transparent;
  color: var(--ink-3);
  cursor: pointer;
  border-radius: var(--r-sm);
}
.pw-toggle:active { background: var(--fill); }
.pw-toggle svg { width: 19px; height: 19px; }

.form-error {
  margin: 0 0 var(--sp-3);
  padding: 11px 13px;
  border-radius: var(--r-md);
  background: #ffecea;
  border: 1px solid #ffc4bf;
  color: #b3261e;
  font-size: 14px;
  line-height: 1.4;
}

/* ---- 按钮 ---- */
.btn-primary {
  width: 100%;
  min-height: var(--tap-min);
  padding: 13px 18px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--accent);
  color: #fff;
  font-family: inherit;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}
.btn-primary:hover { background: var(--accent-press); }
.btn-primary:disabled { opacity: 0.5; cursor: default; }
.btn-primary.compact { width: auto; flex: 1; padding: 11px 18px; font-size: 16px; }

.btn-link {
  display: block;
  width: 100%;
  margin-top: var(--sp-3);
  padding: 10px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
  border-radius: var(--r-sm);
}
.btn-link:active { background: var(--accent-soft); }

.btn-quiet {
  min-height: var(--tap-min);
  padding: 11px 18px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg-2);
  color: var(--ink-2);
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.btn-quiet:hover { background: #fafafa; }
.btn-quiet:active { background: var(--fill); }
.btn-quiet.danger { color: var(--danger); border-color: #ffc4bf; }

/* ============================================================
   模块选择
   ============================================================ */
.hello-block { margin-bottom: var(--sp-5); }
.hello {
  margin: 0 0 4px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.signed-as { margin: 0; font-size: 14px; color: var(--ink-3); }

.section-title {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-2);
}
.section-hint { margin: 0 0 var(--sp-3); font-size: 13px; color: var(--ink-3); }

.module-list { list-style: none; margin: 0 0 var(--sp-5); padding: 0; }

.module-card {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  min-height: 76px;
  margin-bottom: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  background: var(--bg-2);
  box-shadow: var(--shadow-card);
  text-align: left;
  font-family: inherit;
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.module-card:hover { box-shadow: var(--shadow-raise); }
.module-card:active { transform: scale(0.985); }

.module-card.is-disabled {
  cursor: default;
  opacity: 0.62;
  box-shadow: none;
}
.module-card.is-disabled:hover { box-shadow: none; }
.module-card.is-disabled:active { transform: none; }

.module-icon {
  width: 46px; height: 46px;
  flex: 0 0 auto;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.module-body { flex: 1; min-width: 0; }
.module-name {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 2px;
}
.module-desc {
  font-size: 13px;
  color: var(--ink-3);
  line-height: 1.35;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.module-action {
  flex: 0 0 auto;
  font-size: 14px;
  font-weight: 500;
  color: var(--accent);
  white-space: nowrap;
}
.module-tag {
  flex: 0 0 auto;
  padding: 4px 9px;
  border-radius: var(--r-pill);
  background: var(--fill);
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.module-tag.admin-only {
  background: #fff4e5;
  color: #8c5a0a;
}

/* 进入中：细线指示 */
.module-card.is-busy .module-action { opacity: 0.6; }

.account-actions {
  display: flex;
  gap: var(--sp-2);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--line-2);
}
.account-actions .btn-quiet { flex: 1; }

/* ============================================================
   底部弹层（修改密码）
   ============================================================ */
.sheet-mask {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.32);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade 0.18s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  width: 100%;
  max-width: 560px;
  background: var(--bg);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: var(--sp-2) var(--sp-4) calc(var(--sp-5) + env(safe-area-inset-bottom));
  animation: slideUp 0.24s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) {
  .sheet, .sheet-mask { animation: none; }
}

.sheet-grabber {
  width: 36px; height: 5px;
  margin: 4px auto var(--sp-3);
  border-radius: var(--r-pill);
  background: var(--ink-4);
}
.sheet-title {
  margin: 0 0 var(--sp-3);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.sheet .field input { background: var(--bg-2); }
.sheet-actions { display: flex; gap: var(--sp-2); margin-top: var(--sp-4); }

/* ============================================================
   小屏适配
   ============================================================ */
@media (max-width: 400px) {
  html, body { font-size: 16px; }
  .auth-title, .hello { font-size: 25px; }
  .stage { padding-left: var(--sp-3); padding-right: var(--sp-3); }
}

/* ============================================================
   找回密码 / 邮箱
   ============================================================ */
.btn-link.subtle {
  margin-top: 2px;
  font-size: 14px;
  color: var(--ink-3);
}

.form-note {
  margin: 0 0 var(--sp-3);
  padding: 11px 13px;
  border-radius: var(--r-md);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  color: #0a3f73;
  font-size: 14px;
  line-height: 1.45;
}

/* ---- 邮箱卡片 ---- */
.email-card {
  margin-bottom: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  background: var(--bg-2);
  box-shadow: var(--shadow-card);
}
.email-row { display: flex; align-items: center; gap: var(--sp-3); }
.email-info { flex: 1; min-width: 0; }
.email-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-3);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.email-value {
  margin-top: 3px;
  font-size: 16px;
  color: var(--ink);
  word-break: break-all;
}
.email-state { margin-top: 4px; font-size: 12px; }
.email-state.is-ok { color: #1a8c39; }
.email-state.is-warn { color: #c96f00; }
.email-form { margin-top: var(--sp-3); }
.btn-quiet.compact { min-height: 38px; padding: 8px 14px; font-size: 14px; flex: 0 0 auto; }

/* ============================================================
   审核状态页 / 管理页
   ============================================================ */

/* ---- 状态页 ---- */
.status-card { text-align: center; padding-top: var(--sp-6); }
.status-icon { font-size: 46px; line-height: 1; margin-bottom: var(--sp-3); }
.status-card .auth-sub { margin-bottom: var(--sp-3); }
.status-body {
  margin: 0 0 var(--sp-3);
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink-2);
  text-align: left;
  background: var(--bg);
  padding: 14px;
  border-radius: var(--r-md);
}

/* ---- 管理页 ----
   ⚠️ 两个布局要点（都踩过）：
   1. #view-admin 必须放在 <main class="stage"> 【内部】。
      曾误放在 </main> 之后 → 它逃出 .stage 的宽度约束、左边距丢失，
      而 .stage 仍占着高度，于是页面顶部出现一大片空白。
   2. 管理页表格需要比 560px 更宽。这里用负外边距"撑破" .stage 的居中栏，
      并用 min() 限制上限；窄屏（<900px）完全不加偏移，避免横向溢出。 */
.admin-view { max-width: none; }

@media (min-width: 900px) {
  .admin-view {
    /* (100vw - 560px)/2 是 .stage 左右两侧的空白，抵消它即可铺开，
       两侧各留 40px 安全间距 */
    margin-left: calc(-1 * max(0px, (100vw - 560px) / 2 - 40px));
    width: min(calc(100vw - 80px), 1100px);
  }
}
.admin-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
}
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: var(--sp-3);
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}
.tab {
  flex: 0 0 auto;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--bg-2);
  color: var(--ink-2);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}
.tab.is-on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.tab-panel[hidden] { display: none; }

.filter-row { display: flex; gap: 6px; margin-bottom: var(--sp-2); flex-wrap: wrap; }
.chip {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--bg-2);
  color: var(--ink-2);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}
.chip.is-on { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); font-weight: 600; }

/* ---- 申请卡片 ---- */
.user-list { list-style: none; margin: 0; padding: 0; }
.user-card {
  padding: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  background: var(--bg-2);
  box-shadow: var(--shadow-card);
}
.user-top { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-2); }
.user-name { font-size: 17px; font-weight: 600; }
.user-meta { font-size: 12px; color: var(--ink-3); margin-top: 4px; line-height: 1.5; word-break: break-all; }
.user-actions { display: flex; gap: var(--sp-2); margin-top: var(--sp-3); }
.user-actions .btn-quiet, .user-actions .btn-primary { flex: 1; min-height: 42px; padding: 9px 12px; font-size: 15px; }
.btn-primary.danger-btn { background: var(--danger); }
.btn-primary.danger-btn:hover { background: #d92b21; }

.status-pill {
  flex: 0 0 auto;
  padding: 3px 9px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.status-pill.s-pending { background: var(--warn); color: #fff; }
.status-pill.s-active { background: var(--ok); color: #fff; }
.status-pill.s-rejected { background: var(--danger); color: #fff; }

/* ---- 表格 ---- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line-2); border-radius: var(--r-lg); background: var(--bg-2); }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td {
  padding: 10px 12px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--line-2);
}
.tbl th { font-size: 12px; font-weight: 600; color: var(--ink-3); background: var(--bg); }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

/* ---- 日志视图 ---- */
.log-view {
  max-height: 60vh;
  overflow: auto;
  margin: 0;
  padding: var(--sp-3);
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  background: #1d1d1f;
  color: #e8e8ed;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
}
.empty { text-align: center; color: var(--ink-3); font-size: 14px; padding: var(--sp-5) 0; }
