/* ===== 基础重置 & 变量 ===== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI Rounded", "Helvetica Neue",
    "PingFang SC", "Microsoft YaHei", "Heiti SC", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

:root {
  --navy: #16213e;
  --navy-light: #22335c;
  --red: #d7263d;
  --red-dark: #a81b2e;
  --gold: #f4b942;
  --bg: #fff9ec;
  --card: #ffffff;
  --card-alt: #fbf3df;
  --ink: #1c1c28;
  --muted: #6b7280;
  --border: #ecdfc0;
  --success: #2f9e63;
  --danger: #d7263d;
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 10px 26px rgba(22, 33, 62, 0.10);
  --shadow-pop: 0 16px 40px rgba(22, 33, 62, 0.22);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --shell-max: 480px;
  --rail-w: 84px;
}

a { color: inherit; }
button { font-family: inherit; }
ul { list-style: none; margin: 0; padding: 0; }

/* ===== App 外壳 ===== */
.app-shell {
  max-width: var(--shell-max);
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.boot-loading {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
}
.boot-badge {
  font-size: 40px;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.15); } }

/* ===== 顶部栏 ===== */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(14px + var(--safe-top)) 18px 14px;
  background: linear-gradient(135deg, var(--navy), var(--navy-light));
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  box-shadow: var(--shadow-card);
}
.top-bar .avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.14);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
  border: 2px solid var(--gold);
}
.top-bar .who { flex: 1; min-width: 0; }
.top-bar .who .name { font-weight: 700; font-size: 16px; }
.top-bar .who .role { font-size: 12px; opacity: 0.75; }
.points-chip {
  display: flex; align-items: center; gap: 6px;
  background: rgba(244,185,66,0.18);
  border: 1px solid var(--gold);
  color: var(--gold);
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
}

/* ===== 主体内容 ===== */
.view-main {
  flex: 1;
  padding: 16px 16px calc(96px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--navy);
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 2px 0;
}

.hint { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 0; }

/* ===== 卡片 ===== */
.card {
  background: var(--card);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border);
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 28px 10px;
  font-size: 14px;
}
.empty-state .icon { font-size: 34px; display: block; margin-bottom: 8px; }

/* 任务卡/奖励卡的外层容器：手机上纵向堆叠，平板上（见下方 @media）变成两列网格 */
.case-grid { display: flex; flex-direction: column; gap: 10px; }

/* ===== 搜索框 ===== */
.search-box { position: relative; margin: 8px 0 4px; }
.search-box .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 15px;
  pointer-events: none;
  opacity: 0.7;
}
.search-input {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px 10px 34px;
  font-size: 15px;
  background: var(--card);
  color: var(--ink);
  font-family: inherit;
}
.search-input:focus { outline: none; border-color: var(--red); }
.search-input::-webkit-search-cancel-button { cursor: pointer; }

/* ===== 按钮 ===== */
.btn {
  border: none;
  border-radius: 999px;
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--red-dark); }
.btn-gold { background: var(--gold); color: var(--navy); }
.btn-navy { background: var(--navy); color: #fff; }
.btn-ghost { background: transparent; color: var(--navy); border: 1.5px solid var(--border); }
.btn-danger { background: transparent; color: var(--danger); border: 1.5px solid var(--danger); }
.btn-sm { padding: 7px 14px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.fab {
  position: fixed;
  right: max(18px, calc((100vw - var(--shell-max)) / 2 + 18px));
  bottom: calc(90px + var(--safe-bottom));
  z-index: 30;
  border-radius: 999px;
  padding: 14px 20px;
  background: var(--red);
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  border: none;
  box-shadow: var(--shadow-pop);
}

/* ===== 底部导航 ===== */
.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: var(--shell-max);
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 8px 8px calc(8px + var(--safe-bottom));
  z-index: 25;
  box-shadow: 0 -6px 18px rgba(22,33,62,0.08);
}
.bottom-nav button {
  flex: 1;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 2px;
  font-size: 11px;
  color: var(--muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.bottom-nav button .icon { font-size: 21px; }
.bottom-nav button.active { color: var(--red); font-weight: 700; background: var(--card-alt); }

/* ===== 表单 ===== */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field textarea, .field select {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 15px;
  background: var(--bg);
  color: var(--ink);
  font-family: inherit;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none;
  border-color: var(--red);
}

/* ===== 标签/徽章 ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
}
.badge-pending { background: #fff2cf; color: #92650b; }
.badge-approved, .badge-applied, .badge-agreed { background: #dff5e6; color: #1c7a45; }
.badge-rejected, .badge-cancelled { background: #fde3e6; color: #a81b2e; }
.badge-waiting { background: #e6ecfb; color: #2a4bb0; }

/* ===== 列表项 ===== */
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.list-item .li-icon {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--card-alt);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.list-item .li-body { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 700; font-size: 14.5px; }
.list-item .li-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.list-item .li-side { text-align: right; flex-shrink: 0; }

/* ===== Toast ===== */
.toast-root {
  position: fixed;
  top: calc(14px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 420px);
  pointer-events: none;
}
.toast {
  background: var(--navy);
  color: #fff;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  box-shadow: var(--shadow-pop);
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-error { background: var(--red-dark); }
.toast-success { background: var(--success); }

/* ===== 模态框 ===== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,20,35,0.55);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 90; padding: 0;
}
.modal-sheet {
  background: var(--card);
  width: 100%; max-width: var(--shell-max);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px 18px calc(20px + var(--safe-bottom));
  box-shadow: var(--shadow-pop);
  max-height: 88vh;
  overflow-y: auto;
}
.modal-sheet h3 { margin: 0 0 12px; color: var(--navy); }

/* ===== 登录页 ===== */
.login-page { display: flex; flex-direction: column; gap: 20px; padding: calc(28px + var(--safe-top)) 20px 28px; flex: 1; justify-content: center; }
.login-title { text-align: center; }
.login-title h1 { margin: 6px 0 2px; color: var(--navy); font-size: 22px; }
.login-title p { margin: 0; color: var(--muted); font-size: 13px; }
.avatar-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.avatar-pick {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  cursor: pointer;
  box-shadow: var(--shadow-card);
}
.avatar-pick .emo { font-size: 30px; }
.avatar-pick .nm { font-size: 12.5px; font-weight: 700; text-align: center; }
.avatar-pick:active { transform: scale(0.96); }

.pinpad-wrap { display: flex; flex-direction: column; align-items: center; gap: 20px; }
.pin-dots { display: flex; gap: 12px; }
.pin-dots .dot {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--navy);
}
.pin-dots .dot.filled { background: var(--red); border-color: var(--red); }
.pin-dots.shake { animation: shake 0.4s; }
@keyframes shake { 20%,60% { transform: translateX(-8px);} 40%,80% { transform: translateX(8px);} }
.pin-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; width: 100%; max-width: 300px; }
.pin-key {
  padding: 16px 0;
  font-size: 20px;
  font-weight: 700;
  border-radius: var(--radius-md);
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
}
.pin-key:active { transform: scale(0.94); }
.pin-key.wide { font-size: 14px; }

/* ===== 通用工具类 ===== */
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.text-center { text-align: center; }
.muted { color: var(--muted); }
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--red);
  animation: spin 0.8s linear infinite;
  margin: 20px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 平板适配（≥768px）=====
   1) 内容区放宽，不再挤成手机宽度的一小条；
   2) 底部Tab栏在登录后变成左侧竖排导航栏（平板上更顺手，也把底部空间还给内容）；
   3) 卡片列表在宽屏下用两列排布，减少留白。
   登录页没有导航栏，不受这条影响，仍然是居中的单栏。 */
@media (min-width: 768px) {
  :root { --shell-max: 900px; }

  .app-shell.with-nav { padding-left: var(--rail-w); }

  .view-main { padding: 18px 20px calc(28px + var(--safe-bottom)); }

  .bottom-nav {
    top: 0;
    bottom: 0;
    left: max(0px, calc((100vw - var(--shell-max)) / 2));
    transform: none;
    width: var(--rail-w);
    max-width: var(--rail-w);
    height: 100dvh;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 6px;
    padding: calc(20px + var(--safe-top)) 6px calc(16px + var(--safe-bottom));
    border-top: none;
    border-right: 1px solid var(--border);
    box-shadow: 6px 0 18px rgba(22,33,62,0.06);
  }
  .bottom-nav button { flex: none; padding: 12px 2px; }
  .bottom-nav button .icon { font-size: 23px; }

  .fab { bottom: calc(24px + var(--safe-bottom)); }

  .modal-backdrop { align-items: center; }
  .modal-sheet {
    max-width: 560px;
    border-radius: var(--radius-lg);
    padding: 24px 24px calc(24px + var(--safe-bottom));
    max-height: 80vh;
  }

  .login-page { max-width: 420px; margin: 0 auto; }

  .case-grid { display: grid; grid-template-columns: repeat(2, 1fr); }
}
