/* ==========================================================================
   app.css — 布局、组件与移动交互
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  /* iOS Safari：彻底锁死横向滚动/橡皮筋，避免页面被轻微拖动后不回弹 */
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overscroll-behavior-x: none;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* 禁止横向拖动整页（纵向保留，交给内部滚动容器） */
  touch-action: pan-y;
}

body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  /* 键盘弹出时避免整页被推上去 */
  position: fixed;
  inset: 0;
  overflow: hidden;
}

body.no-scroll { overflow: hidden; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; background: none; border: none; padding: 0; }

a { color: var(--primary-deep); text-decoration: none; }

mark {
  background: var(--warn-soft);
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
}

::selection { background: var(--primary-tint); }

/* ————————————————— 应用外壳 ————————————————— */

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  /* 使用 dvh 让软键盘出现时布局正确收缩；
     vh 作为旧版 Safari 的兜底，避免高度抖动 */
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: pan-y;
}

.app-header {
  flex: 0 0 auto;
  padding-top: var(--sa-top);
  background: var(--bg-glass);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--divider);
  z-index: 30;
}

.app-header__inner {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 max(var(--sp-4), var(--sa-left)) 0 max(var(--sp-4), var(--sa-right));
}

.app-header__title {
  flex: 1;
  min-width: 0;
  font-size: var(--fs-lg);
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-header__sub {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 400;
  color: var(--fg-subtle);
  margin-top: 1px;
}

.icon-btn {
  width: var(--tap-min);
  height: var(--tap-min);
  min-width: var(--tap-min);
  display: grid;
  place-items: center;
  border-radius: var(--r-full);
  font-size: 17px;
  color: var(--fg-muted);
  transition: background var(--dur) var(--ease);
}
.icon-btn:active { background: var(--primary-tint); }
.icon-btn--badge { position: relative; }
.icon-btn--badge::after {
  content: '';
  position: absolute;
  top: 9px; right: 9px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 2px var(--bg);
}

.app-main {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: var(--sp-4) max(var(--sp-4), var(--sa-left)) var(--sp-8) max(var(--sp-4), var(--sa-right));
  scrollbar-width: none;
}
.app-main::-webkit-scrollbar { display: none; }
.app-main:focus { outline: none; }

/* 底部导航 */
.app-nav {
  flex: 0 0 auto;
  display: flex;
  align-items: stretch;
  padding-bottom: var(--sa-bottom);
  background: var(--bg-glass);
  backdrop-filter: saturate(160%) blur(16px);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  border-top: 1px solid var(--divider);
  z-index: 30;
}

.app-nav__item {
  flex: 1;
  min-height: var(--nav-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: var(--fs-xs);
  color: var(--fg-faint);
  transition: color var(--dur) var(--ease);
  position: relative;
}
.app-nav__item.is-active { color: var(--primary-deep); font-weight: 600; }
.app-nav__item.is-active::before {
  content: '';
  position: absolute;
  top: 0;
  width: 22px; height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--primary);
}
.app-nav__icon { font-size: 18px; line-height: 1; }

/* 悬浮按钮 —— 拇指可达 */
.fab {
  position: fixed;
  right: max(var(--sp-4), var(--sa-right));
  bottom: calc(var(--nav-h) + var(--sa-bottom) + var(--sp-4));
  width: 54px; height: 54px;
  border-radius: var(--r-full);
  display: grid;
  place-items: center;
  font-size: 24px;
  color: var(--fg-on-primary);
  background: linear-gradient(145deg, var(--primary), var(--primary-deep));
  box-shadow: var(--shadow-fab);
  z-index: 25;
  transition: transform 160ms var(--ease);
}
.fab:active { transform: scale(0.94); }
.fab.is-hidden { display: none; }

/* 底部操作栏 */
.action-bar {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--nav-h) + var(--sa-bottom));
  height: var(--action-bar-h);
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-3) max(var(--sp-4), var(--sa-left)) var(--sp-3) max(var(--sp-4), var(--sa-right));
  background: var(--bg-elevated);
  border-top: 1px solid var(--divider);
  box-shadow: 0 -4px 16px rgba(74, 58, 63, 0.06);
  z-index: 26;
  animation: slideUp 220ms var(--ease);
}
.action-bar__btn {
  flex: 1;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--r-sm);
  background: var(--bg-sunken);
  color: var(--fg-muted);
  font-size: var(--fs-sm);
  font-weight: 550;
}
.action-bar__btn.is-primary { background: var(--primary); color: var(--fg-on-primary); }
.action-bar__btn:active { transform: scale(0.97); }

/* 多选模式条 */
.select-bar {
  position: fixed;
  left: 0; right: 0; top: 0;
  padding: calc(var(--sa-top) + var(--sp-3)) max(var(--sp-4), var(--sa-left)) var(--sp-3) max(var(--sp-4), var(--sa-right));
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  background: var(--primary-soft);
  border-bottom: 1px solid var(--border);
  z-index: 40;
  animation: slideDown 200ms var(--ease);
}
.select-bar__count { flex: 1; font-weight: 600; color: var(--primary-deep); }

@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes slideDown { from { transform: translateY(-100%); } to { transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ————————————————— 卡片与列表 ————————————————— */

.card {
  background: var(--bg-elevated);
  border-radius: var(--r-lg);
  padding: var(--sp-4);
  margin-bottom: var(--sp-3);
  box-shadow: var(--shadow-sm);
  border: 1px solid transparent;
  transition: box-shadow var(--dur) var(--ease), transform 140ms var(--ease);
}
.card--tappable:active { transform: scale(0.985); box-shadow: var(--shadow-md); }
.card--flat { box-shadow: none; border-color: var(--border); }
.card--highlight { background: var(--primary-soft); border-color: var(--primary-tint); }
.card--glass {
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.card__head {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  margin-bottom: var(--sp-2);
}
.card__title {
  flex: 1;
  min-width: 0;
  font-size: var(--fs-md);
  font-weight: 620;
  line-height: var(--lh-tight);
}
.card__meta {
  font-size: var(--fs-xs);
  color: var(--fg-subtle);
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: var(--sp-1);
}
.card__body { font-size: var(--fs-sm); color: var(--fg-muted); }
.card__foot {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-top: var(--sp-3);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--divider);
  font-size: var(--fs-xs);
  color: var(--fg-subtle);
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  margin: var(--sp-5) 0 var(--sp-3);
}
.section-title:first-child { margin-top: var(--sp-1); }
.section-title__text {
  margin: 0;
  font-size: var(--fs-md);
  font-weight: 650;
  letter-spacing: -0.01em;
}

.list { display: flex; flex-direction: column; gap: var(--sp-2); }

.list-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: var(--tap-min);
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-elevated);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  transition: transform 140ms var(--ease), background var(--dur) var(--ease);
}
.list-row:active { transform: scale(0.988); }
.list-row--selected { background: var(--primary-soft); box-shadow: 0 0 0 1.5px var(--primary) inset; }
.list-row__main { flex: 1; min-width: 0; }
.list-row__title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row__sub { font-size: var(--fs-xs); color: var(--fg-subtle); margin-top: 2px; }
.list-row__chev { color: var(--fg-faint); font-size: 14px; }

/* 滑动操作（左滑露出按钮，绝不直接删除） */
.swipe-item {
  position: relative;
  overflow: hidden;
  border-radius: var(--r-md);
}
.swipe-item__actions {
  position: absolute;
  inset: 0 0 0 auto;
  display: flex;
}
.swipe-item__btn {
  width: 78px;
  display: grid;
  place-items: center;
  gap: 2px;
  font-size: var(--fs-xs);
  color: #fff;
  background: var(--primary);
}
.swipe-item__btn--danger { background: var(--danger); }
.swipe-item__btn--warn { background: var(--warn); }
.swipe-item__content {
  position: relative;
  background: var(--bg-elevated);
  transition: transform 200ms var(--ease);
  z-index: 1;
}

/* ————————————————— 徽标与状态 ————————————————— */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: var(--r-full);
  font-size: 10.5px;
  font-weight: 600;
  background: var(--bg-sunken);
  color: var(--fg-muted);
  white-space: nowrap;
}
.badge--primary { background: var(--primary-soft); color: var(--primary-deep); }
.badge--success { background: var(--success-soft); color: #2F7A52; }
.badge--warn { background: var(--warn-soft); color: #94641A; }
.badge--danger { background: var(--danger-soft); color: #A44; }
.badge--info { background: var(--info-soft); color: #3F6288; }
.badge--muted { background: transparent; border: 1px solid var(--border); color: var(--fg-subtle); }
.badge--ai { background: var(--accent-soft); color: #6A5A78; }

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  display: inline-block;
  background: var(--fg-faint);
}
.status-dot--online { background: var(--success); }
.status-dot--offline { background: var(--warn); }
.status-dot--error { background: var(--danger); }
.status-dot--syncing { background: var(--info); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* 应用级状态横幅 */
.status-banner {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  font-size: var(--fs-xs);
  background: var(--warn-soft);
  color: #7A5A1F;
  border-bottom: 1px solid var(--border);
}
.status-banner--error { background: var(--danger-soft); color: #8A3A3A; }
.status-banner--info { background: var(--info-soft); color: #3F6288; }
.status-banner--success { background: var(--success-soft); color: #2F5A41; }

/* ————————————————— 表单 ————————————————— */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-4); }
.field--wide { grid-column: 1 / -1; }
.field__label { font-size: var(--fs-sm); font-weight: 600; color: var(--fg-muted); }
.field__hint { font-size: var(--fs-xs); color: var(--fg-subtle); line-height: var(--lh-normal); }

.input {
  width: 100%;
  min-height: var(--tap-min);
  padding: 10px var(--sp-3);
  border-radius: var(--r-sm);
  border: 1.5px solid var(--border);
  background: var(--bg-elevated);
  color: var(--fg);
  font-size: var(--fs-base);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  /* 16px 以下 iOS 会自动放大页面，这里用 transform 方案规避 */
  -webkit-appearance: none;
  appearance: none;
}
.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-tint);
}
.input--area { min-height: 88px; resize: vertical; line-height: var(--lh-normal); }
.input::placeholder { color: var(--fg-faint); }
select.input { background-image: none; }

.form-grid { display: grid; grid-template-columns: 1fr; gap: 0 var(--sp-3); }
@media (min-width: 560px) { .form-grid { grid-template-columns: 1fr 1fr; } }

.switch {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: var(--tap-min);
  cursor: pointer;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track {
  position: relative;
  width: 46px; height: 28px;
  border-radius: var(--r-full);
  background: var(--border-strong);
  transition: background var(--dur) var(--ease);
  flex: none;
}
.switch__track::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur) var(--ease);
}
.switch input:checked + .switch__track { background: var(--primary); }
.switch input:checked + .switch__track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch__track { box-shadow: 0 0 0 3px var(--primary-tint); }
.switch__label { font-size: var(--fs-base); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 var(--sp-4);
  border-radius: var(--r-sm);
  font-size: var(--fs-base);
  font-weight: 600;
  transition: transform 140ms var(--ease), opacity var(--dur) var(--ease);
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.btn--primary { background: var(--primary); color: var(--fg-on-primary); }
.btn--ghost { background: var(--bg-sunken); color: var(--fg-muted); }
.btn--outline { background: transparent; border: 1.5px solid var(--border-strong); color: var(--fg-muted); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--sm { min-height: 34px; padding: 0 12px; font-size: var(--fs-sm); }
.btn--block { width: 100%; }

.chip-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: var(--r-full);
  background: var(--bg-sunken);
  border: 1.5px solid transparent;
  font-size: var(--fs-sm);
  color: var(--fg-muted);
  transition: all var(--dur) var(--ease);
}
.chip.is-active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-deep); font-weight: 600; }
.chip--removable { padding-right: 6px; }

/* 分段控件 */
.segmented {
  display: flex;
  padding: 3px;
  background: var(--bg-sunken);
  border-radius: var(--r-sm);
  gap: 2px;
}
.segmented__item {
  flex: 1;
  min-height: 34px;
  border-radius: 9px;
  font-size: var(--fs-sm);
  font-weight: 550;
  color: var(--fg-subtle);
  transition: all var(--dur) var(--ease);
}
.segmented__item.is-active {
  background: var(--bg-elevated);
  color: var(--fg);
  box-shadow: var(--shadow-sm);
}

/* ————————————————— 空 / 错 / 加载状态 ————————————————— */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--sp-2);
  padding: var(--sp-8) var(--sp-5);
  color: var(--fg-subtle);
}
.empty__icon { font-size: 34px; opacity: 0.5; }
.empty__title { font-size: var(--fs-md); font-weight: 600; color: var(--fg-muted); }
.empty__msg { margin: 0; font-size: var(--fs-sm); line-height: var(--lh-normal); max-width: 30em; }
.empty--error .empty__icon { color: var(--danger); opacity: 0.8; }
.empty .btn { margin-top: var(--sp-3); }

.skeleton { display: flex; flex-direction: column; gap: var(--sp-3); padding: var(--sp-4); }
.skeleton__line {
  height: 14px;
  border-radius: 7px;
  background: linear-gradient(90deg, var(--bg-sunken) 25%, var(--primary-soft) 50%, var(--bg-sunken) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--primary-tint);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 下拉刷新 */
.pull-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  height: 0;
  overflow: hidden;
  font-size: var(--fs-xs);
  color: var(--fg-subtle);
  transition: height 180ms var(--ease);
}
.pull-indicator.is-active { height: 40px; }

/* ————————————————— 便签条 —— 用于「这是 AI 生成」等标注 ————————————————— */

.notice {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-3);
  border-radius: var(--r-sm);
  font-size: var(--fs-xs);
  line-height: var(--lh-normal);
  background: var(--info-soft);
  color: #375877;
  border-left: 3px solid var(--info);
}
.notice--warn { background: var(--warn-soft); color: #7A5A1F; border-left-color: var(--warn); }
.notice--danger { background: var(--danger-soft); color: #8A3A3A; border-left-color: var(--danger); }
.notice--ai { background: var(--accent-soft); color: #5F4F6D; border-left-color: var(--accent); }
.notice--symbolic { background: var(--primary-soft); color: #7A4A52; border-left-color: var(--primary); }
.notice__icon { flex: none; font-size: 13px; }

/* ————————————————— 统计与图表 ————————————————— */

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-2); }
@media (min-width: 480px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 720px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }

.stat {
  background: var(--bg-elevated);
  border-radius: var(--r-md);
  padding: var(--sp-3);
  box-shadow: var(--shadow-sm);
}
.stat__label { font-size: var(--fs-xs); color: var(--fg-subtle); }
.stat__value { font-size: var(--fs-xl); font-weight: 680; letter-spacing: -0.02em; margin-top: 2px; }
.stat__unit { font-size: var(--fs-sm); font-weight: 500; color: var(--fg-subtle); margin-left: 2px; }
.stat--primary { background: var(--primary-soft); }
.stat--tappable:active { transform: scale(0.98); }

.bar-chart { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding: var(--sp-2) 0; }
.bar-chart__col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  min-width: 0;
}
.bar-chart__bar {
  width: 100%;
  max-width: 26px;
  border-radius: 5px 5px 2px 2px;
  background: linear-gradient(180deg, var(--primary), var(--primary-deep));
  min-height: 3px;
  transition: height 400ms var(--ease);
}
.bar-chart__label { font-size: 9.5px; color: var(--fg-faint); white-space: nowrap; }

.line-chart { width: 100%; height: auto; display: block; overflow: visible; }
.line-chart .grid-line { stroke: var(--divider); stroke-width: 1; }
.line-chart .axis-label { font-size: 9px; fill: var(--fg-faint); }
.line-chart .series { fill: none; stroke: var(--primary); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.line-chart .series-area { fill: var(--primary-tint); stroke: none; }
.line-chart .point { fill: var(--bg-elevated); stroke: var(--primary); stroke-width: 2; cursor: pointer; }

.heat-grid { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr); gap: 3px; }
.heat-cell { width: 100%; aspect-ratio: 1; border-radius: 2.5px; background: var(--bg-sunken); }

/* ————————————————— 时间线 ————————————————— */

.timeline { position: relative; padding-left: 26px; }
.timeline::before {
  content: '';
  position: absolute;
  left: 7px; top: 6px; bottom: 6px;
  width: 1.5px;
  background: linear-gradient(180deg, var(--primary-tint), var(--divider) 60%, transparent);
}
.timeline__item { position: relative; margin-bottom: var(--sp-4); }
.timeline__item::before {
  content: '';
  position: absolute;
  left: -24px; top: 6px;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 3px var(--bg);
}
.timeline__item--muted::before { background: var(--border-strong); }
.timeline__date { font-size: var(--fs-xs); color: var(--fg-subtle); margin-bottom: 4px; }

/* ————————————————— 聊天气泡 ————————————————— */

.chat-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-4) 0;
}

.msg { display: flex; flex-direction: column; max-width: 88%; }
.msg--user { align-self: flex-end; align-items: flex-end; }
.msg--assistant { align-self: flex-start; align-items: flex-start; }
.msg--system { align-self: center; max-width: 96%; }

.msg__bubble {
  padding: 10px var(--sp-3);
  border-radius: var(--r-md);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  position: relative;
}
.msg--user .msg__bubble {
  background: var(--primary);
  color: var(--fg-on-primary);
  border-bottom-right-radius: 5px;
}
.msg--assistant .msg__bubble {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
  box-shadow: var(--shadow-sm);
}
.msg--system .msg__bubble {
  background: var(--bg-sunken);
  color: var(--fg-subtle);
  font-size: var(--fs-xs);
  text-align: center;
  border-radius: var(--r-sm);
  padding: 6px var(--sp-3);
}
.msg--selected .msg__bubble { box-shadow: 0 0 0 2px var(--primary); }
.msg--stale { opacity: 0.5; }
.msg--stale .msg__bubble::after {
  content: '（已封存分支）';
  font-size: 10px;
  color: var(--fg-faint);
  display: block;
  margin-top: 4px;
}

.msg__meta {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: 10.5px;
  color: var(--fg-faint);
  margin: 3px 4px 0;
  flex-wrap: wrap;
}
.msg__tools {
  display: flex;
  gap: var(--sp-1);
  opacity: 0.7;
}
.msg__tool {
  padding: 2px 6px;
  border-radius: var(--r-xs);
  font-size: 10.5px;
  color: var(--fg-subtle);
  background: var(--bg-sunken);
}
.msg__tool:active { background: var(--primary-soft); }

.msg__role-tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 7px;
  border-radius: var(--r-full);
  font-size: 10px;
  font-weight: 600;
  background: var(--accent-soft);
  color: #6A5A78;
  margin-bottom: 4px;
}

.typing { display: inline-flex; gap: 3px; align-items: center; height: 18px; }
.typing span {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--primary);
  animation: bounce 1.1s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.16s; }
.typing span:nth-child(3) { animation-delay: 0.32s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-5px); opacity: 1; } }

/* 聊天输入区 —— 必须不被键盘、底部导航、操作条遮挡 */
.chat-composer {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--nav-h) + var(--sa-bottom) + var(--action-bar-h));
  z-index: 27;
  padding: var(--sp-2) max(var(--sp-3), var(--sa-left)) calc(var(--sp-2) + var(--kb-inset)) max(var(--sp-3), var(--sa-right));
  background: var(--bg-glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--divider);
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
}
.chat-composer .input {
  min-height: 42px;
  max-height: 132px;
  padding: 10px var(--sp-3);
  border-radius: var(--r-lg);
  resize: none;
  line-height: 1.4;
}
.chat-composer__send {
  width: 42px; height: 42px;
  flex: none;
  border-radius: 50%;
  background: var(--primary);
  color: var(--fg-on-primary);
  display: grid;
  place-items: center;
  font-size: 17px;
}
.chat-composer__send:disabled { background: var(--border-strong); }

/* 上下文预览 */
.context-preview {
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--bg-sunken);
  overflow: hidden;
  margin-bottom: var(--sp-2);
}
.context-preview__head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--fg-muted);
  cursor: pointer;
}
.context-preview__body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 260ms var(--ease);
}
.context-preview.is-open .context-preview__body { max-height: 320px; overflow-y: auto; }
.context-block { padding: var(--sp-2) var(--sp-3); border-top: 1px solid var(--divider); }
.context-block__head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: 10.5px;
  font-weight: 650;
  color: var(--fg-subtle);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.context-block__count { font-weight: 400; color: var(--fg-faint); }
.context-block__text {
  font-size: var(--fs-xs);
  color: var(--fg-muted);
  white-space: pre-wrap;
  max-height: 96px;
  overflow-y: auto;
  margin-top: 3px;
  line-height: var(--lh-normal);
}

/* ————————————————— 弹层 ————————————————— */

.modal-overlay, .sheet-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 100;
  display: flex;
  opacity: 0;
  transition: opacity 200ms var(--ease);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.modal-overlay.is-in, .sheet-overlay.is-in { opacity: 1; }
.modal-overlay { align-items: center; justify-content: center; padding: var(--sp-5); }
.sheet-overlay { align-items: flex-end; }

.modal {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elevated);
  border-radius: var(--r-xl);
  padding: var(--sp-5);
  box-shadow: var(--shadow-lg);
  transform: scale(0.94);
  transition: transform 220ms var(--ease);
}
.modal-overlay.is-in .modal { transform: scale(1); }
.modal__title { margin: 0 0 var(--sp-2); font-size: var(--fs-lg); font-weight: 650; }
.modal__message { margin: 0; font-size: var(--fs-sm); color: var(--fg-muted); line-height: var(--lh-normal); }
.modal__detail {
  margin: var(--sp-3) 0 0;
  padding: var(--sp-3);
  background: var(--bg-sunken);
  border-radius: var(--r-sm);
  font-size: var(--fs-xs);
  font-family: var(--font-sans);
  white-space: pre-wrap;
  color: var(--fg-subtle);
  max-height: 180px;
  overflow-y: auto;
  line-height: var(--lh-normal);
}
.modal__actions { display: flex; gap: var(--sp-2); margin-top: var(--sp-5); }
.modal__actions .btn { flex: 1; }

.sheet {
  width: 100%;
  max-height: 92dvh;
  background: var(--bg-elevated);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 260ms var(--ease);
  padding-bottom: var(--sa-bottom);
  box-shadow: var(--shadow-lg);
}
.sheet-overlay.is-in .sheet { transform: translateY(0); }
.sheet__grabber {
  width: 38px; height: 4px;
  border-radius: 2px;
  background: var(--border-strong);
  margin: 8px auto 0;
  flex: none;
  touch-action: none;
}
.sheet__head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--divider);
}
.sheet__title { flex: 1; margin: 0; font-size: var(--fs-md); font-weight: 650; }
.sheet__close {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--fg-subtle);
  background: var(--bg-sunken);
  font-size: 13px;
}
.sheet__body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--sp-4);
}
.sheet__foot {
  flex: none;
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--divider);
  background: var(--bg-elevated);
}
.sheet__foot .btn { flex: 1; }

/* ————————————————— Toast ————————————————— */

.toast-host {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--nav-h) + var(--sa-bottom) + var(--sp-4));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  z-index: 200;
  pointer-events: none;
  padding: 0 var(--sp-4);
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  max-width: 460px;
  width: fit-content;
  padding: 10px var(--sp-4);
  border-radius: var(--r-full);
  background: var(--fg);
  color: var(--bg);
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 200ms var(--ease), transform 200ms var(--ease);
}
.toast.is-in { opacity: 1; transform: translateY(0); }
.toast--success { background: var(--success); color: #fff; }
.toast--warn { background: var(--warn); color: #fff; }
.toast--error { background: var(--danger); color: #fff; }
.toast__icon { flex: none; }
.toast__text { line-height: 1.4; }
.toast__action {
  margin-left: var(--sp-2);
  padding: 3px 10px;
  border-radius: var(--r-full);
  background: rgba(255, 255, 255, 0.2);
  color: inherit;
  font-size: var(--fs-xs);
  font-weight: 600;
}

/* ————————————————— 向导 ————————————————— */

.wizard {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.wizard__head {
  flex: none;
  padding: calc(var(--sa-top) + var(--sp-4)) max(var(--sp-5), var(--sa-left)) var(--sp-3) max(var(--sp-5), var(--sa-right));
}
.wizard__step {
  font-size: var(--fs-xs);
  color: var(--fg-subtle);
  font-weight: 600;
  letter-spacing: 0.04em;
}
.wizard__title { margin: var(--sp-2) 0 0; font-size: var(--fs-xl); font-weight: 680; letter-spacing: -0.02em; }
.wizard__desc { margin: var(--sp-2) 0 0; font-size: var(--fs-sm); color: var(--fg-muted); line-height: var(--lh-normal); }
.wizard__progress {
  display: flex;
  gap: 4px;
  margin-top: var(--sp-4);
}
.wizard__progress > i {
  flex: 1;
  height: 3px;
  border-radius: 2px;
  background: var(--border);
  transition: background 300ms var(--ease);
}
.wizard__progress > i.is-done { background: var(--primary); }

.wizard__body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--sp-5) max(var(--sp-5), var(--sa-left)) var(--sp-4) max(var(--sp-5), var(--sa-right));
}
.wizard__foot {
  flex: none;
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-3) max(var(--sp-5), var(--sa-left)) calc(var(--sp-3) + var(--sa-bottom) + var(--kb-inset)) max(var(--sp-5), var(--sa-right));
  border-top: 1px solid var(--divider);
  background: var(--bg-elevated);
}
.wizard__foot .btn { flex: 1; }

.choice-card {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border-radius: var(--r-md);
  border: 1.5px solid var(--border);
  background: var(--bg-elevated);
  margin-bottom: var(--sp-3);
  text-align: left;
  transition: all var(--dur) var(--ease);
  width: 100%;
}
.choice-card.is-active {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 3px var(--primary-tint);
}
.choice-card__icon { font-size: 20px; flex: none; }
.choice-card__main { flex: 1; min-width: 0; }
.choice-card__title { font-weight: 650; font-size: var(--fs-base); display: flex; align-items: center; gap: 6px; }
.choice-card__desc { font-size: var(--fs-xs); color: var(--fg-muted); margin-top: 3px; line-height: var(--lh-normal); }

/* ————————————————— 工具类 ————————————————— */

.row { display: flex; align-items: center; gap: var(--sp-2); }
.row--between { justify-content: space-between; }
.row--wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: var(--sp-2); }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--fg-subtle); }
.faint { color: var(--fg-faint); }
.small { font-size: var(--fs-sm); }
.tiny { font-size: var(--fs-xs); }
.bold { font-weight: 650; }
.mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }
.mb-2 { margin-bottom: var(--sp-2); }
.mb-3 { margin-bottom: var(--sp-3); }
.mb-4 { margin-bottom: var(--sp-4); }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pre-wrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.hidden { display: none !important; }
.mono { font-family: var(--font-mono); font-size: var(--fs-xs); }
.divider { height: 1px; background: var(--divider); margin: var(--sp-4) 0; }
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* 横屏适配 */
@media (orientation: landscape) and (max-height: 500px) {
  :root { --nav-h: 48px; --header-h: 44px; }
  .app-nav__item { min-height: 48px; }
  .fab { bottom: calc(var(--nav-h) + var(--sa-bottom) + var(--sp-2)); width: 46px; height: 46px; font-size: 20px; }
  .wizard__body { padding-top: var(--sp-4); }
}

/* 大屏：居中约束，避免平板/桌面下拉伸 */
@media (min-width: 768px) {
  .app-header__inner, .app-main, .chat-composer, .app-nav, .status-banner {
    max-width: 720px;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
  }
  .app-nav { justify-content: center; }
  .app-nav__item { max-width: 140px; }
  .fab { right: calc(50% - 360px + var(--sp-4)); }
  .toast-host { bottom: var(--sp-6); }
}

/* ==========================================================================
   启动屏 / 致命错误屏
   ========================================================================== */

.boot {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: calc(var(--sp-8) + var(--sa-top)) var(--sp-6) calc(var(--sp-8) + var(--sa-bottom));
  text-align: center;
  background: var(--bg);
}
.boot__logo {
  font-size: 42px;
  color: var(--primary);
  animation: bootPulse 2.2s ease-in-out infinite;
}
.boot__title { font-size: var(--fs-xl); font-weight: var(--fw-semibold); color: var(--fg); letter-spacing: 0.02em; }
.boot__msg { font-size: var(--fs-sm); color: var(--fg-muted); max-width: 30ch; line-height: 1.7; }
.boot__detail { font-size: var(--fs-xs); color: var(--fg-subtle); max-width: 34ch; line-height: 1.6; }
.boot__bar { width: 140px; height: 3px; border-radius: 3px; background: var(--primary-tint); overflow: hidden; margin-top: var(--sp-2); }
.boot__bar span {
  display: block; height: 100%; width: 40%;
  background: var(--primary); border-radius: 3px;
  animation: bootSlide 1.4s ease-in-out infinite;
}
.boot--error .boot__logo { color: var(--warn); animation: none; }
.boot__actions { display: flex; gap: var(--sp-3); margin-top: var(--sp-3); }
.boot__actions button {
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--radius-md);
  border: 1px solid var(--primary);
  background: var(--primary);
  color: var(--fg-on-primary);
  font-size: var(--fs-sm);
  font-family: inherit;
  cursor: pointer;
}
.boot__actions button + button { background: transparent; color: var(--primary); }
.boot__trace {
  margin-top: var(--sp-5); text-align: left; max-width: 100%;
  font-size: var(--fs-xs); color: var(--fg-subtle);
}
.boot__trace summary { cursor: pointer; }
.boot__trace pre {
  white-space: pre-wrap; word-break: break-all;
  background: var(--bg-sunken); padding: var(--sp-3);
  border-radius: var(--radius-sm); max-height: 240px; overflow: auto;
}
@keyframes bootPulse { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: .6; transform: scale(.94); } }
@keyframes bootSlide { 0% { transform: translateX(-110%); } 100% { transform: translateX(360%); } }
@media (prefers-reduced-motion: reduce) {
  .boot__logo, .boot__bar span { animation: none; }
}

/* ==========================================================================
   Tabs / 分段控件滚动变体
   ========================================================================== */

.tab-body { padding-bottom: 24px; }

.segmented--scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  flex-wrap: nowrap;
  justify-content: flex-start;
  margin-bottom: var(--sp-4);
}
.segmented--scroll::-webkit-scrollbar { display: none; }
.segmented--scroll .segmented__item { flex: 0 0 auto; white-space: nowrap; }

.segmented--sm .segmented__item { padding: 4px 8px; font-size: var(--fs-xs); }

/* ==========================================================================
   键值行 / 表格 / 统计
   ========================================================================== */

.kv { display: flex; align-items: flex-start; gap: var(--sp-3); padding: 7px 0; font-size: var(--fs-sm); }
.kv + .kv { border-top: 1px solid var(--divider); }
.kv__k { color: var(--fg-subtle); flex: 0 0 42%; }
.kv__v { color: var(--fg); flex: 1; text-align: right; word-break: break-word; }

.table { font-size: var(--fs-sm); }
.table__row { display: flex; justify-content: space-between; gap: var(--sp-3); padding: 7px 0; }
.table__row + .table__row { border-top: 1px solid var(--divider); }
.table__row .mono { color: var(--fg-subtle); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-3);
}
.stat {
  background: var(--bg-sunken);
  border-radius: var(--radius-md);
  padding: var(--sp-3);
  text-align: center;
}
.stat__value { font-size: var(--fs-lg); font-weight: var(--fw-semibold); color: var(--primary-deep); line-height: 1.3; }
.stat__label { font-size: var(--fs-xs); color: var(--fg-muted); margin-top: 2px; }
.stat__sub { font-size: 10px; color: var(--fg-subtle); margin-top: 2px; }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3) 0; }
.row-between + .row-between { border-top: 1px solid var(--divider); }
.row-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-top: var(--sp-2); }
.row-actions--stack { flex-direction: column; }
.row-actions--stack .btn { width: 100%; }
.row-actions--wrap { flex-wrap: wrap; }

/* 开关行（原生 DOM 版） */
.switch-row {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) 0; cursor: pointer;
}
.switch-row + .switch-row { border-top: 1px solid var(--divider); }
.switch-row > div:first-child { flex: 1; min-width: 0; }
.switch-row input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 42px; height: 24px; border-radius: 12px;
  background: var(--divider); position: relative;
  transition: background .2s ease; flex: 0 0 auto; cursor: pointer;
}
.switch-row input[type="checkbox"]::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; transition: transform .2s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,.18);
}
.switch-row input[type="checkbox"]:checked { background: var(--primary); }
.switch-row input[type="checkbox"]:checked::after { transform: translateX(18px); }
.switch-row .switch { display: none; }

.number-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3); padding: var(--sp-3) 0;
}
.number-row + .number-row { border-top: 1px solid var(--divider); }
.number-row > div:first-child { flex: 1; min-width: 0; }
.input--num { width: 88px; text-align: center; flex: 0 0 auto; }

.field { display: block; margin-bottom: var(--sp-3); }
.field__label { display: block; font-size: var(--fs-sm); color: var(--fg-muted); margin-bottom: var(--sp-2); }
.textarea {
  width: 100%; padding: var(--sp-3);
  border: 1px solid var(--divider); border-radius: var(--radius-md);
  background: var(--bg-sunken); color: var(--fg);
  font-family: inherit; font-size: var(--fs-sm); line-height: 1.7;
  resize: vertical; min-height: 68px;
}
.textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; background: var(--bg-elevated); }

/* ==========================================================================
   主题色板 / 连接行 / 授权行
   ========================================================================== */

.theme-row { display: flex; gap: var(--sp-3); overflow-x: auto; padding: var(--sp-1) 0; scrollbar-width: none; }
.theme-row::-webkit-scrollbar { display: none; }
.theme-swatch {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  background: none; border: none; padding: 4px; cursor: pointer;
  font-family: inherit; flex: 0 0 auto;
}
.theme-swatch__dot {
  width: 44px; height: 44px; border-radius: 50%;
  border: 2px solid transparent; box-shadow: 0 1px 4px rgba(0,0,0,.1);
  transition: border-color .18s ease, transform .18s ease;
}
.theme-swatch.is-active .theme-swatch__dot { border-color: var(--primary); transform: scale(1.06); }
.theme-swatch .small { color: var(--fg-muted); }

.conn-row {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-3) 0;
}
.conn-row + .conn-row { border-top: 1px solid var(--divider); }
.conn-row__main { flex: 1; min-width: 0; }
.conn-row__name { font-weight: var(--fw-medium); font-size: var(--fs-sm); }
.conn-row__actions { display: flex; gap: var(--sp-1); flex: 0 0 auto; }
.conn-row__main .mono { word-break: break-all; }
.req-url {
  margin-top: 2px; padding: 4px 6px;
  font-size: 11px; line-height: 1.45;
  color: var(--fg-muted);
  background: var(--bg-sunken, rgba(127, 127, 127, .1));
  border-radius: 6px;
  word-break: break-all;
  user-select: all;               /* 长按即可整段复制 */
  -webkit-user-select: all;
}
.tag--warn {
  display: inline-block; margin-top: 4px; padding: 2px 8px;
  font-size: 11px; border-radius: 999px;
  color: var(--fg-warning, #b26a00);
  background: color-mix(in srgb, var(--fg-warning, #b26a00) 14%, transparent);
}

.provider-note { padding: var(--sp-3) 0; }
.provider-note + .provider-note { border-top: 1px solid var(--divider); }
.provider-note__title { font-size: var(--fs-sm); font-weight: var(--fw-medium); margin-bottom: 2px; }

.scope-row {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) 0; flex-wrap: wrap;
}
.scope-row + .scope-row { border-top: 1px solid var(--divider); }
.scope-row__main { flex: 1 1 140px; min-width: 0; }

.proactive-row { padding: var(--sp-3) 0; }
.proactive-row + .proactive-row { border-top: 1px solid var(--divider); }
.proactive-row__head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }

.audit-row { padding: var(--sp-3); border-radius: var(--radius-md); background: var(--bg-sunken); margin-bottom: var(--sp-3); }
.audit-row__head { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-2); }
.audit-row__text { font-size: var(--fs-sm); line-height: 1.7; margin-bottom: var(--sp-2); white-space: pre-wrap; }

/* ==========================================================================
   提醒中心
   ========================================================================== */

.due-row {
  padding: var(--sp-3) 0;
}
.due-row + .due-row { border-top: 1px solid var(--divider); }
.due-row__head { display: flex; align-items: flex-start; gap: var(--sp-3); margin-bottom: var(--sp-2); }
.due-row__icon { font-size: 20px; flex: 0 0 auto; line-height: 1.4; }
.due-row__title { font-weight: var(--fw-medium); font-size: var(--fs-sm); }

/* ==========================================================================
   收藏 / 关联
   ========================================================================== */

.bookmark-row { padding: var(--sp-3) 0; }
.bookmark-row + .bookmark-row { border-top: 1px solid var(--divider); }
.bookmark-row__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-2); }
.bookmark-row__title { font-weight: var(--fw-medium); font-size: var(--fs-sm); flex: 1; min-width: 0; }
.bookmark-row__text {
  font-size: var(--fs-sm); color: var(--fg-muted); line-height: 1.7;
  margin: var(--sp-2) 0; white-space: pre-wrap; word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.chip--static { cursor: default; }
.chip--muted { opacity: .62; }
.icon-btn {
  background: none; border: none; font-size: 17px; color: var(--fg-subtle);
  padding: 2px 6px; cursor: pointer; font-family: inherit; border-radius: 6px;
}
.icon-btn:active { background: var(--primary-tint); }

.relation-row { padding: var(--sp-3) 0; }
.relation-row + .relation-row { border-top: 1px solid var(--divider); }
.relation-row__snap {
  font-size: var(--fs-sm); line-height: 1.7; color: var(--fg);
  white-space: pre-wrap; word-break: break-word; margin-bottom: var(--sp-1);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

.list-row.danger { color: var(--danger, #C0392B); }

/* ==========================================================================
   附件
   ========================================================================== */

.attachment-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-2); margin-bottom: var(--sp-4);
}
.attachment-tile {
  background: var(--bg-elevated); border: 1px solid var(--divider);
  border-radius: var(--radius-md); padding: 0; overflow: hidden;
  cursor: pointer; font-family: inherit; text-align: left;
  display: flex; flex-direction: column;
}
.attachment-tile__img {
  width: 100%; aspect-ratio: 1; object-fit: cover; display: block;
  background: var(--bg-sunken);
}
.attachment-tile__file {
  width: 100%; aspect-ratio: 1; display: flex; align-items: center;
  justify-content: center; font-size: 26px; background: var(--bg-sunken);
}
.attachment-tile__meta { padding: 5px 6px; }
.attachment-tile__name {
  font-size: 10px; color: var(--fg-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.attachment-tile__meta .small { font-size: 9px; }
.attachment-preview { width: 100%; border-radius: var(--radius-md); margin-bottom: var(--sp-3); }

/* ==========================================================================
   帮助页
   ========================================================================== */

.help-section { scroll-margin-top: calc(var(--header-h) + var(--sp-4)); }
.help-body { font-size: var(--fs-sm); line-height: 1.8; color: var(--fg-muted); }
.help-p { margin: 0 0 var(--sp-2); }
.help-spacer { height: var(--sp-2); }
.help-li { margin: 0 0 5px; padding-left: var(--sp-2); }
.help-quote {
  border-left: 3px solid var(--primary);
  background: var(--primary-tint);
  padding: var(--sp-3); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: var(--sp-3) 0; color: var(--fg);
}
.help-tr {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  gap: var(--sp-2); padding: 7px 0;
  border-bottom: 1px solid var(--divider);
  align-items: start;
}
.help-td { font-size: var(--fs-xs); }
.help-body strong { color: var(--fg); font-weight: var(--fw-semibold); }
.code {
  background: var(--bg-sunken); padding: 1px 5px; border-radius: 4px;
  font-family: var(--font-mono); font-size: 0.9em;
}
.link-list { display: flex; flex-direction: column; }
.link-row {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) 0; text-decoration: none; color: var(--fg);
  font-size: var(--fs-sm);
}
.link-row + .link-row { border-top: 1px solid var(--divider); }
.link-row > span:first-child { width: 22px; flex: 0 0 auto; }
.link-row > span:nth-child(2) { flex: 1; }
.link-row__chev { color: var(--fg-subtle); }

/* ==========================================================================
   自检
   ========================================================================== */

.test-row {
  padding: var(--sp-3);
  border-radius: var(--radius-md);
  margin-bottom: var(--sp-2);
  border-left: 3px solid var(--divider);
  background: var(--bg-elevated);
}
.test-row--running { opacity: .62; border-left-color: var(--accent); }
.test-row--pass { border-left-color: var(--success); }
.test-row--fail { border-left-color: var(--warn); background: var(--warn-soft); }
.test-row--skip { border-left-color: var(--fg-subtle); }
.test-row__head { display: flex; align-items: center; gap: var(--sp-2); }
.test-row__icon { font-size: 15px; flex: 0 0 auto; }
.test-row--pass .test-row__icon { color: var(--success); }
.test-row--fail .test-row__icon { color: var(--warn); }
.test-row__name { flex: 1; font-size: var(--fs-sm); font-weight: var(--fw-medium); min-width: 0; }
.test-row__detail {
  font-size: var(--fs-xs); color: var(--fg-muted);
  margin-top: var(--sp-2); line-height: 1.7; white-space: pre-wrap; word-break: break-word;
}
.test-row__manual {
  font-size: var(--fs-xs); color: var(--accent);
  margin-top: 5px; padding: 5px 8px;
  background: var(--accent-soft); border-radius: var(--radius-sm);
}

.pre-wrap { white-space: pre-wrap; word-break: break-word; line-height: 1.7; }

/* ==========================================================================
   错误状态
   ========================================================================== */

.error-state { padding: var(--sp-6) var(--sp-4); text-align: center; }
.error-state h3 { font-size: var(--fs-base); margin-bottom: var(--sp-2); }
.error-state p { font-size: var(--fs-sm); color: var(--fg-muted); margin-bottom: var(--sp-2); }
.error-state pre {
  text-align: left; font-size: var(--fs-xs);
  background: var(--bg-sunken); padding: var(--sp-3);
  border-radius: var(--radius-sm); white-space: pre-wrap; word-break: break-all;
  max-height: 220px; overflow: auto;
}

/* ==========================================================================
   小屏细化
   ========================================================================== */

@media (max-width: 360px) {
  .stat-grid { grid-template-columns: 1fr 1fr; gap: var(--sp-2); }
  .attachment-grid { grid-template-columns: repeat(2, 1fr); }
  .kv__k { flex-basis: 46%; }
}

@media (min-width: 768px) {
  .test-row, .audit-row, .help-section { max-width: 720px; margin-left: auto; margin-right: auto; }
}
