/* ==========================================================================
   暖邻社区 · 基础样式与适老化布局
   ========================================================================== */
* { box-sizing: border-box; -webkit-tap-highlight-color: rgba(31, 122, 92, 0.12); }

html {
  font-size: var(--fs-base);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-3);
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  letter-spacing: 0.01em;
}

h1, h2, h3, h4 { margin: 0 0 0.5em; line-height: 1.35; font-weight: 700; }
h1 { font-size: var(--fs-5); }
h2 { font-size: var(--fs-4); }
h3 { font-size: var(--fs-4); }
h4 { font-size: var(--fs-3); }
p { margin: 0 0 0.75em; }
a { color: var(--brand-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
ul, ol { padding-left: 1.3em; margin: 0 0 0.8em; }
small { font-size: var(--fs-1); }
hr { border: none; border-top: 1px solid var(--line); margin: 18px 0; }

:focus-visible {
  outline: 3px solid var(--warm);
  outline-offset: 2px;
  border-radius: 6px;
}

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--brand); color: #fff; padding: 12px 18px; border-radius: 0 0 var(--r-sm) 0;
}
.skip-link:focus { left: 0; }

/* ---------------- 顶栏 ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 8px;
  min-height: var(--topbar-h);
  padding: 8px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.topbar-title {
  flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center;
}
#page-title {
  font-size: var(--fs-4); font-weight: 700; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#page-sub { font-size: var(--fs-1); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 6px; flex: none; }
.topbar-btn {
  min-width: var(--tap); min-height: 44px; padding: 0 12px;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-sm);
  font-size: var(--fs-2); cursor: pointer; position: relative;
}
.topbar-btn:hover { background: var(--brand-soft); border-color: var(--brand-line); }
.dot-badge {
  position: absolute; top: 2px; right: 2px; min-width: 18px; height: 18px;
  background: var(--danger); color: #fff; border-radius: var(--r-pill);
  font-size: 12px; line-height: 18px; text-align: center; padding: 0 4px;
}

/* ---------------- 主体 ---------------- */
.page-wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: var(--gap) var(--gap) calc(var(--tabbar-h) + 30px);
}
.page { min-height: 40vh; }
.app-footer {
  margin-top: 26px; padding-top: 14px; border-top: 1px dashed var(--line);
  font-size: var(--fs-1); color: var(--ink-3); text-align: center;
}
.link-btn {
  background: none; border: none; color: var(--brand-strong);
  text-decoration: underline; cursor: pointer; font-size: inherit; padding: 4px;
}

/* 底部导航 */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  display: flex; justify-content: space-around; align-items: stretch;
  min-height: var(--tabbar-h);
  background: var(--card);
  border-top: 1px solid var(--line);
  box-shadow: 0 -2px 12px rgba(20, 60, 45, 0.07);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 8px 2px; color: var(--ink-3); font-size: var(--fs-1); text-decoration: none;
  position: relative; min-width: 0;
}
.tabbar a .ti { font-size: 1.5rem; line-height: 1; }
.tabbar a span.tl { white-space: nowrap; }
.tabbar a.active { color: var(--brand-strong); font-weight: 700; background: var(--brand-soft); }
.tabbar a.active .ti { transform: translateY(-1px); }
.tabbar a .tab-badge {
  position: absolute; top: 4px; right: 50%; margin-right: -22px;
  background: var(--danger); color: #fff; font-size: 11px; line-height: 16px;
  min-width: 16px; height: 16px; border-radius: var(--r-pill); padding: 0 4px; text-align: center;
}

/* 浮动语音按钮 */
.fab {
  position: fixed; right: 14px; bottom: calc(var(--tabbar-h) + 14px); z-index: 44;
  width: 62px; height: 62px; border-radius: 50%;
  background: var(--warm); color: #fff; border: none; cursor: pointer;
  font-size: 1.6rem; box-shadow: var(--shadow-lg);
}
.fab.listening { background: var(--danger); animation: pulse 1.1s infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }

/* 小屏适配：顶栏只留标题，语气副标题省略；浮动按钮缩小并避开卡片内容 */
@media (max-width: 560px) {
  .topbar { padding: 6px 8px; gap: 6px; }
  .topbar-actions { gap: 4px; }
  .topbar-btn { min-width: 42px; padding: 0 8px; }
  #page-sub { display: none; }
  .fab { width: 52px; height: 52px; font-size: 1.35rem; right: 10px; bottom: calc(var(--tabbar-h) + 10px); }
  .kpi { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* 加载与遮罩 */
.loading-mask {
  position: fixed; inset: 0; z-index: 70; background: rgba(20, 40, 33, 0.28);
  display: flex; align-items: center; justify-content: center;
}
/* hidden 属性必须生效，否则遮罩会一直盖在页面上挡住点击 */
.loading-mask[hidden] { display: none !important; }
.loading-box {
  background: var(--card); border-radius: var(--r); padding: 22px 30px;
  display: flex; align-items: center; gap: 12px; box-shadow: var(--shadow-lg);
}
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 4px solid var(--brand-soft); border-top-color: var(--brand);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 大字模式下的紧凑修正 */
html[data-fontsize="4"] .topbar-actions { gap: 4px; }
html[data-fontsize="4"] .tabbar a { font-size: 0.72rem; }

/* 打印（生成纸质版周报/作品集） */
@media print {
  .topbar, .tabbar, .fab, .app-footer { display: none !important; }
  body { background: #fff; }
  .page-wrap { max-width: none; padding: 0; }
}

@media (max-width: 380px) {
  :root { --gap: 10px; }
  .topbar { padding: 6px 8px; }
}
