/* 应用级外壳与通用组件。设计 token 与 SwiftUI Theme.swift 对齐。 */

/* ---------- 外壳 ---------- */
.app {
  background: #fff;
  color: var(--ink);
}

.app-view {
  padding: 0 0 calc(72px + env(safe-area-inset-bottom));
  min-height: 100vh;
  min-height: 100dvh;
}

.page {
  padding: 0 var(--page) calc(88px + env(safe-area-inset-bottom));
}

/* ---------- 底部主导航 ---------- */
.main-tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 40;
  width: 100%;
  max-width: var(--sheet);
  transform: translateX(-50%);
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  height: calc(64px + env(safe-area-inset-bottom));
  padding: 6px 6px env(safe-area-inset-bottom);
  background: rgba(255, 255, 255, 0.94);
  border-top: 1px solid rgba(238, 241, 247, 0.9);
  backdrop-filter: saturate(1.8) blur(18px);
  -webkit-backdrop-filter: saturate(1.8) blur(18px);
  transition: transform 0.25s ease, opacity 0.25s ease;
}
.main-tabbar.is-hidden { transform: translate(-50%, 110%); opacity: 0; pointer-events: none; }

.mtab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 4px 0 3px;
  color: #9AA3B2;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1px;
}
.mtab.is-active { color: var(--brand-deep); }
.mtab-icon { position: relative; width: 27px; height: 27px; display: grid; place-items: center; }
.mtab-icon svg { width: 26px; height: 26px; fill: currentColor; stroke: none; }
.mtab-badge {
  position: absolute;
  top: -4px;
  right: -8px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: #F04444;
  border: 1.5px solid #fff;
  color: #fff;
  font-size: 9px;
  font-style: normal;
  font-weight: 800;
  line-height: 14px;
  text-align: center;
}
.mtab-badge[hidden] { display: none; }

.mtab-plus {
  flex: 0 0 auto;
  width: 56px;
  height: 56px;
  margin: -20px 2px 4px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--brand-grad);
  color: #fff;
  box-shadow: 0 8px 20px rgba(80, 110, 230, 0.35), 0 0 0 5px rgba(255, 255, 255, 0.92);
  transition: transform 0.14s;
}
.mtab-plus:active { transform: scale(0.93); }
.mtab-plus svg { width: 28px; height: 28px; stroke-width: 2.2; fill: none; stroke: currentColor; }

/* ---------- 首页顶部导航 ---------- */
.home-nav {
  position: sticky;
  top: 0;
  z-index: 24;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 10px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: saturate(1.8) blur(16px);
  -webkit-backdrop-filter: saturate(1.8) blur(16px);
}

.nav-icon {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--ink);
}
.nav-icon:active { background: var(--field); }

/* 顶部分段控件 */
.seg {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--track);
}
.seg-item {
  height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  color: #7D8797;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: color 0.18s, background 0.18s;
}
.seg-item.is-active {
  color: #fff;
  background: var(--brand-grad);
  box-shadow: 0 4px 11px rgba(80, 110, 230, 0.3);
}

/* 横向胶囊标签栏 */
.pill-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 0;
  background: #fff;
  border-bottom: 1px solid var(--divider);
}
.pill-scroll {
  flex: 1;
  display: flex;
  gap: 2px;
  overflow-x: auto;
  padding: 0 4px 0 14px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.pill-scroll::-webkit-scrollbar { display: none; }
.pill {
  flex: 0 0 auto;
  height: 32px;
  padding: 0 8px;
  border-radius: 999px;
  color: #7D8797;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}
.pill.is-active {
  color: #fff;
  background: var(--brand-grad);
  box-shadow: 0 4px 11px rgba(80, 110, 230, 0.28);
}
.trailing-more {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 30px;
  padding: 0 12px;
  margin-right: 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, #FBFCFF, #F4F7FD);
  border: 1px solid #E3E9F5;
  color: #5A6578;
  font-size: 12px;
  font-weight: 600;
}

/* ---------- 详情页导航 ---------- */
.detail-nav {
  position: sticky;
  top: 0;
  z-index: 24;
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  align-items: center;
  min-height: 52px;
  padding: 0 8px;
  background: rgba(255, 255, 255, 0.95);
  border-bottom: 1px solid var(--divider);
  backdrop-filter: saturate(1.8) blur(16px);
  -webkit-backdrop-filter: saturate(1.8) blur(16px);
}
.detail-nav-title { min-width: 0; text-align: center; line-height: 1.2; }
.detail-nav-title strong { display: block; font-size: 16px; font-weight: 800; letter-spacing: -0.2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-nav-title span { display: block; margin-top: 2px; font-size: 10px; color: var(--sub); }
.detail-nav-right { display: flex; justify-content: flex-end; align-items: center; }
.nav-spacer { width: 36px; }
.nav-link { color: var(--brand-deep); font-size: 13px; font-weight: 600; padding: 8px; }

/* ---------- 通用按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 44px;
  padding: 0 16px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.1px;
  transition: transform 0.12s, opacity 0.12s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); opacity: 0.94; }
.btn-primary { background: var(--brand-grad); color: #fff; box-shadow: 0 6px 16px rgba(80, 110, 230, 0.26); }
.btn-ghost { background: #fff; border: 1px solid var(--border); color: #4B566B; }
.btn-on-dark { background: rgba(255, 255, 255, 0.16); border: 1px solid rgba(255, 255, 255, 0.22); color: #fff; backdrop-filter: blur(8px); }
.btn-danger { background: rgba(240, 69, 69, 0.08); color: var(--danger); border: 1px solid rgba(240, 69, 69, 0.16); }
.btn-sm { height: 36px; padding: 0 13px; border-radius: 12px; font-size: 12.5px; }
.btn-xs { height: 28px; padding: 0 10px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.danger-btn { color: var(--danger); border-color: rgba(240, 69, 69, 0.2); }

/* ---------- 头像 ---------- */
.ava {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  color: #fff;
  font-weight: 800;
  line-height: 1;
  overflow: hidden;
  vertical-align: middle;
}
.ava img { width: 100%; height: 100%; object-fit: cover; }
.ava.is-shadow { box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); }
.ava-stack { display: inline-flex; align-items: center; flex: 0 0 auto; height: var(--ava, 18px); }
.ava-stack .ava { margin-left: calc(var(--ava) * -0.28); border: 2px solid #fff; }
.ava-stack .ava:first-child { margin-left: 0; }

/* ---------- 标签 ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 8px;
  border-radius: 7px;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}
.chip-gray { background: #F1F4F9; color: #6B768A; }
.chip-blue { background: #EDF4FF; color: #3F7FDB; }
.chip-green { background: #EAF8EF; color: #138A4E; }
.chip-orange { background: #FFF1E6; color: #C25E12; }
.chip-purple { background: #F3EDFF; color: #7140C9; }
.chip-gold { background: #FFF6DF; color: #A77608; }
.chip-red { background: #FDECEC; color: #C04343; }

.id-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  border-radius: 5px;
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  line-height: 1.4;
}
.id-opc { background: linear-gradient(135deg, #F0A020, #D9930D); }
.id-green { background: linear-gradient(135deg, #18A45C, #0D9B5F); }

.mini-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 11px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--border);
  color: #6B768A;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.mini-chip.is-done { color: var(--green); border-color: rgba(13, 155, 95, 0.22); background: rgba(13, 155, 95, 0.06); }

/* ---------- 分区与列表 ---------- */
.home-section { margin-top: 16px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 10px; }
.section-title { display: flex; align-items: baseline; gap: 7px; font-size: 17px; font-weight: 800; letter-spacing: -0.3px; }
.section-title span { color: var(--sub); font-size: 11px; font-weight: 500; }
.link-more { display: inline-flex; align-items: center; gap: 2px; color: var(--sub); font-size: 11px; font-weight: 600; padding: 4px 0; }

.filter-row { display: flex; gap: 7px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.filter-row::-webkit-scrollbar { display: none; }
.filter-pill {
  flex: 0 0 auto;
  height: 30px;
  padding: 0 13px;
  border-radius: 999px;
  background: #F3F5F9;
  color: #6B768A;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.filter-pill.is-active { background: #1E2A44; color: #fff; }

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 12px;
  border-radius: 14px;
  background: #F7F8FB;
  border: 1px solid var(--border);
  color: var(--faint);
}
.search-box input { flex: 1; min-width: 0; border: 0; background: none; outline: none; font-size: 16px; color: var(--ink); }
.search-box input::placeholder { color: var(--faint); }

/* ---------- 弹层 ---------- */
.overlay { position: fixed; inset: 0; z-index: 60; }
.overlay .mask {
  position: absolute;
  inset: 0;
  background: rgba(16, 27, 48, 0.46);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: fadeIn 0.18s ease;
}
.sheet-wrap {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 100%;
  max-width: var(--sheet);
  transform: translateX(-50%);
  animation: sheetUp 0.26s cubic-bezier(0.22, 0.8, 0.3, 1);
}
.sheet-card {
  width: 100%;
  max-height: var(--sheet-max, 86vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #fff;
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -14px 40px rgba(16, 27, 48, 0.16);
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
}
.sheet-head {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #fff;
  padding: 7px 14px 4px;
  border-radius: 22px 22px 0 0;
}
.sheet-grab { width: 36px; height: 4px; margin: 0 auto 7px; border-radius: 999px; background: #DDE3EC; }
.sheet-head-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 32px; }
.sheet-head-row strong { font-size: 16px; font-weight: 800; letter-spacing: -0.2px; }
.sheet-head-row span { display: block; margin-top: 2px; font-size: 10.5px; color: var(--sub); }
.sheet-body { padding: 8px 16px 16px; }
.sheet-title { margin: 6px 0 10px; font-size: 20px; font-weight: 900; letter-spacing: -0.4px; line-height: 1.3; }

.full-panel {
  position: fixed;
  inset: 0;
  max-width: var(--sheet);
  margin: 0 auto;
  background: #fff;
  overflow-y: auto;
  animation: sheetUp 0.26s cubic-bezier(0.22, 0.8, 0.3, 1);
}

@keyframes fadeIn { from { opacity: 0; } }
@keyframes sheetUp { from { transform: translate(-50%, 40px); opacity: 0; } }

/* ---------- 表单 ---------- */
.field { margin-bottom: 13px; }
.field label { display: block; margin: 0 0 6px 2px; font-size: 11px; font-weight: 700; color: var(--sub); }
.field input, .field textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: 13px;
  border: 1px solid var(--border);
  background: var(--field);
  font-size: 16px;
  line-height: 1.5;
  outline: none;
  resize: none;
}
.field textarea { min-height: 90px; }
.field input:focus, .field textarea:focus { border-color: rgba(63, 142, 247, 0.5); background: #fff; }
.choice-row { display: flex; gap: 8px; flex-wrap: wrap; }
.choice {
  height: 34px;
  padding: 0 13px;
  border-radius: 10px;
  background: var(--field);
  border: 1px solid var(--border);
  color: #5A6578;
  font-size: 12px;
  font-weight: 600;
}
.choice.is-active { color: var(--brand-deep); background: #EDF3FF; border-color: rgba(63, 142, 247, 0.35); }

.notice {
  padding: 11px 12px;
  border-radius: 12px;
  background: #FFF7ED;
  border: 1px solid #FBE3C8;
  color: #92500E;
  font-size: 11.5px;
  line-height: 1.65;
}

/* ---------- 空状态 ---------- */
.empty-state { padding: 32px 18px; border-radius: 16px; background: #fff; border: 1px dashed var(--border-soft); text-align: center; }
.empty-state b { display: block; font-size: 14px; font-weight: 800; }
.empty-state p { margin: 6px 0 14px; font-size: 11.5px; color: var(--sub); line-height: 1.6; }

/* ---------- 抽屉 ---------- */
.drawer-overlay .mask { opacity: 0.9; }
.conv-drawer {
  position: absolute;
  left: 50%;
  top: 0;
  width: min(302px, 86vw);
  max-width: var(--sheet);
  height: 100%;
  transform: translateX(-50%) translateX(calc(-1 * min(151px, 43vw)));
  background: #fff;
  border-radius: 0 22px 22px 0;
  box-shadow: 18px 0 50px rgba(16, 27, 48, 0.18);
  padding: calc(18px + env(safe-area-inset-top)) 14px;
  animation: drawerIn 0.24s ease;
  display: flex;
  flex-direction: column;
}
@keyframes drawerIn { from { transform: translateX(-120%); opacity: 0.6; } }
.drawer-head { display: flex; align-items: center; gap: 10px; padding-bottom: 14px; border-bottom: 1px solid var(--divider); }
.drawer-head > div { flex: 1; min-width: 0; }
.drawer-head strong { display: block; font-size: 14px; font-weight: 800; }
.drawer-head span { display: block; margin-top: 2px; font-size: 10px; color: var(--sub); }
.drawer-title { margin: 16px 4px 8px; font-size: 10.5px; font-weight: 800; letter-spacing: 0.08em; color: var(--faint); text-transform: uppercase; }
.drawer-row { display: flex; align-items: center; gap: 9px; width: 100%; padding: 11px 8px; border-radius: 11px; color: #3B475C; font-size: 13px; text-align: left; }
.drawer-row.is-active { background: #EDF4FF; color: var(--brand-deep); }
.drawer-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); flex: 0 0 auto; }
.drawer-row strong { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-row em { font-style: normal; font-size: 9.5px; color: var(--faint); }
.drawer-foot { margin-top: auto; padding-top: 12px; }
.drawer-foot .btn { width: 100%; height: 42px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  z-index: 90;
  max-width: min(340px, calc(100vw - 32px));
  padding: 10px 15px;
  border-radius: 12px;
  background: rgba(16, 27, 48, 0.92);
  color: #fff;
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 桌面居中 ---------- */
@media (min-width: 480px) {
  body { padding: 18px 0; }
  .app { min-height: calc(100vh - 36px); border-radius: 28px; }
  .main-tabbar { bottom: 18px; border-radius: 0 0 28px 28px; }
  .sheet-wrap { bottom: 18px; }
  .sheet-card { border-radius: 22px; padding-bottom: 16px; }
  .sheet-head { border-radius: 22px 22px 0 0; }
  .full-panel { top: 18px; bottom: 18px; border-radius: 28px; }
}
