/* =========================================================
   呱呱社区 · 组件样式
   ---------------------------------------------------------
   这个文件建立在 styles.css 之后，**只用它定义的设计变量**
   （--surface / --text / --accent / --shadow-sm / --r …），
   不重新定义颜色和圆角。

   为什么这么做：
     设计系统最怕的不是「某个组件丑」，而是**同一件事有两个说法** ——
     这里写 #2F6BFF、那里写 #2F6BFF，看起来一样，
     但改主题时要改两处，而一定会漏一处。
     所有值都从变量取，改一处就全站生效。

   字号刻意克制：正文 15px。手机上一屏能看的行数，
   比单个字「大不大」更影响可读性 —— 字号一大，
   一屏只能放三四行，用户就得不停滑，反而更累。
   ========================================================= */

/* ---------------------------------------------------------
   一、外壳与布局
   --------------------------------------------------------- */

.phone {
  max-width: 460px;
  margin: 0 auto;
  min-height: 100dvh;
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg) 240px);
  position: relative;
  display: flex;
  flex-direction: column;
}

.app-root {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* 首屏骨架 */
.boot {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 40px 20px;
}
.boot-logo {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  box-shadow: var(--shadow-sm);
}
.boot-name {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: .5px;
}
.boot-tip {
  font-size: 13px;
  color: var(--text-3);
}

/* 页面容器：头部固定 + 内容滚动 */
.page {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.page-head {
  flex: none;
  padding: 14px 16px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-top);
  /* 头部跟着内容滚的时候会「浮」在内容上方，需要一点分隔感。
     用极淡的边框而不是投影 —— 投影在滚动时会有明显的「脏边」。 */
  border-bottom: 1px solid var(--line-2);
}

.page-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 14px 24px;
  /* 底部留出导航栏的高度，否则最后一条内容会被挡住 */
  padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px));
}

.page-body.no-tabbar {
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}

/* ---------------------------------------------------------
   二、底部导航
   --------------------------------------------------------- */
.tabbar {
  flex: none;
  display: flex;
  background: var(--surface);
  /* ★ 投影朝上。用朝下的话阴影落在栏体下方、也就是屏幕外，
     等于白加 —— 这一条是旧项目里踩过的。 */
  box-shadow: var(--shadow-up);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 20;
}
.tabbar[hidden] { display: none; }

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 4px 7px;
  border: 0;
  background: none;
  color: var(--text-3);
  font-size: 11px;
  cursor: pointer;
  position: relative;
  transition: color .16s ease;
  -webkit-tap-highlight-color: transparent;
}
.tab.on { color: var(--accent); }
.tab svg { width: 22px; height: 22px; }

/* 未读小红点 */
.tab-dot {
  position: absolute;
  top: 6px;
  left: 50%;
  margin-left: 6px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 0 2px var(--surface);
}

/* ---------------------------------------------------------
   三、卡片 / 列表
   --------------------------------------------------------- */
.card {
  background: var(--surface);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
  padding: 14px;
  margin-bottom: 10px;
}

.card-flat {
  background: var(--surface);
  border-radius: var(--r);
  border: 1px solid var(--line);
  padding: 14px;
  margin-bottom: 10px;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-3);
  padding: 4px 2px 8px;
  letter-spacing: .3px;
}

.row-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  background: var(--surface);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
  margin-bottom: 8px;
  cursor: pointer;
  border: 0;
  width: 100%;
  text-align: left;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.row-item:active { background: var(--surface-2); }

.row-main { flex: 1; min-width: 0; }
.row-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-sub {
  font-size: 13px;
  color: var(--text-3);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-arrow { color: var(--text-3); flex: none; }
.row-arrow svg { width: 18px; height: 18px; display: block; }

/* ---------------------------------------------------------
   四、头像
   --------------------------------------------------------- */
.avatar {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  object-fit: cover;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 32px; height: 32px; border-radius: 10px; font-size: 13px; }
.avatar-lg { width: 64px; height: 64px; border-radius: 18px; font-size: 22px; }

/* ---------------------------------------------------------
   五、按钮
   --------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 16px;
  border-radius: 12px;
  border: 0;
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: opacity .15s ease, background .15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active:not(:disabled) { background: #2457d6; }
.btn-ghost {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
}
.btn-soft { background: var(--accent-soft); color: var(--accent); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-block { display: flex; width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 10px; }

/* 图标按钮（头部返回等） */
.icon-btn {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 0;
  background: transparent;
  color: var(--text-2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active { background: var(--surface-3); }
.icon-btn svg { width: 20px; height: 20px; }

/* ---------------------------------------------------------
   六、表单
   --------------------------------------------------------- */
.field { margin-bottom: 12px; }
.field-label {
  display: block;
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 6px;
  font-weight: 500;
}
.field-input,
.field-textarea {
  width: 100%;
  padding: 12px 13px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  transition: border-color .15s ease, box-shadow .15s ease;
  /* iOS 上 input 默认有个内阴影，去掉才和设计一致 */
  -webkit-appearance: none;
  appearance: none;
}
.field-input:focus,
.field-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field-textarea { min-height: 96px; resize: vertical; line-height: 1.6; }
.field-hint { font-size: 12px; color: var(--text-3); margin-top: 5px; }
.field-err { font-size: 12px; color: var(--red); margin-top: 5px; }

/* 隐藏原生 file input，用按钮触发 */
.file-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* ---------------------------------------------------------
   七、帖子
   --------------------------------------------------------- */
.post-card {
  background: var(--surface);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
}
.post-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.post-author { font-size: 14px; font-weight: 500; color: var(--text); }
.post-time { font-size: 12px; color: var(--text-3); }
.post-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
  margin-bottom: 5px;
}
.post-body {
  font-size: 15px;
  color: var(--text-2);
  line-height: 1.62;
  white-space: pre-wrap;
  word-break: break-word;
}
.post-body.clamp {
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.post-img {
  margin-top: 10px;
  width: 100%;
  border-radius: 12px;
  display: block;
  background: var(--surface-3);
}
.post-foot {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line-2);
  font-size: 13px;
  color: var(--text-3);
}
.post-act {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  padding: 2px 0;
  -webkit-tap-highlight-color: transparent;
}
.post-act.on { color: var(--red); }
.post-act svg { width: 17px; height: 17px; }

/* ---------------------------------------------------------
   八、评论
   --------------------------------------------------------- */
.cmt {
  display: flex;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line-2);
}
.cmt:last-child { border-bottom: 0; }
.cmt-main { flex: 1; min-width: 0; }
.cmt-head { display: flex; align-items: baseline; gap: 8px; }
.cmt-name { font-size: 14px; font-weight: 500; color: var(--text); }
.cmt-time { font-size: 12px; color: var(--text-3); }
.cmt-body {
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.6;
  margin-top: 3px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------------------------------------------------------
   九、聊天
   --------------------------------------------------------- */
.chat-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg { display: flex; gap: 8px; align-items: flex-end; }
.msg-me { flex-direction: row-reverse; }

.msg-bubble {
  max-width: 74%;
  padding: 9px 13px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  word-break: break-word;
  white-space: pre-wrap;
}
/* 自己发的一侧用主色。
   圆角刻意做成「一角收小」—— 这个角指向发送者，
   让连续多条消息能看出归属，不需要额外的箭头。 */
.msg-me .msg-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.msg:not(.msg-me) .msg-bubble { border-bottom-left-radius: 5px; }

.msg-img {
  max-width: 60%;
  border-radius: 14px;
  display: block;
}
.msg-time {
  font-size: 11px;
  color: var(--text-3);
  flex: none;
  padding-bottom: 3px;
}

.chat-input-bar {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  box-shadow: var(--shadow-up);
}
.chat-input {
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  padding: 10px 13px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 15px;
  font-family: inherit;
  line-height: 1.45;
  resize: none;
  -webkit-appearance: none;
  appearance: none;
}
.chat-input:focus { outline: none; border-color: var(--accent); background: var(--surface); }

/* 实时状态条：告诉用户现在是「实时」还是「轮询」。
   不显示的话，用户不知道消息为什么来得慢。 */
.rt-status {
  flex: none;
  font-size: 12px;
  color: var(--text-3);
  text-align: center;
  padding: 5px 10px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line-2);
}
.rt-status.live { color: var(--green); }
.rt-status.polling { color: var(--amber); }
.rt-status.failed { color: var(--red); }

/* ---------------------------------------------------------
   十、状态提示
   --------------------------------------------------------- */
.empty {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-3);
  font-size: 14px;
  line-height: 1.7;
}
.empty-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  color: var(--text-3);
  opacity: .5;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-row { padding: 28px 0; text-align: center; }

/* 轻提示 */
.toast-host {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 100;
}
.toast {
  max-width: 86%;
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(16, 24, 40, .92);
  color: #fff;
  font-size: 14px;
  line-height: 1.5;
  box-shadow: var(--shadow-lg);
  animation: toastIn .22s ease;
}
.toast.err { background: rgba(240, 68, 56, .95); }
.toast.ok { background: rgba(18, 183, 106, .95); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* 弹层 */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 200;
  animation: fadeIn .18s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modalIn .22s cubic-bezier(.2, .9, .3, 1);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(.94) translateY(8px); }
  to { opacity: 1; transform: none; }
}
.modal-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  padding: 20px 20px 0;
  text-align: center;
}
.modal-text {
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.65;
  padding: 10px 20px 18px;
  text-align: center;
}
.modal-acts {
  display: flex;
  border-top: 1px solid var(--line);
}
.modal-acts .btn {
  flex: 1;
  border-radius: 0;
  padding: 14px;
  background: none;
  color: var(--accent);
  font-size: 15px;
}
.modal-acts .btn + .btn { border-left: 1px solid var(--line); }
.modal-acts .btn.danger { color: var(--red); }
.modal-acts .btn.plain { color: var(--text-2); }

/* ---------------------------------------------------------
   十一、标签 / 徽章
   --------------------------------------------------------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  background: var(--surface-3);
  color: var(--text-2);
  border: 0;
  cursor: pointer;
  font-family: inherit;
}
.chip.on { background: var(--accent-soft); color: var(--accent); }
.chip-row {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 2px 0 10px;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.6;
}
.badge-admin { background: var(--purple-soft); color: var(--purple); }
.badge-ok { background: var(--green-soft); color: var(--green); }
.badge-warn { background: var(--amber-soft); color: var(--amber); }
.badge-off { background: var(--surface-3); color: var(--text-3); }

/* ---------------------------------------------------------
   十二、工具类
   --------------------------------------------------------- */
.mt-0 { margin-top: 0; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.text-2 { color: var(--text-2); }
.text-3 { color: var(--text-3); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.flex { display: flex; }
.flex-1 { flex: 1; min-width: 0; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.center { text-align: center; }
/* ★ 必须补这一条，否则 .center 里的图片会悄悄靠左。
   原因：styles.css 的全局重置里有 `img { display: block; }`，
   而 text-align 只对**行内级**元素生效 —— 块级元素不响应它。
   所以「块级 + 固定宽度」的图片（比如登录页那只青蛙）
   会紧贴左边缘，看起来像没居中。居中只能靠 margin: auto。 */
.center > img { margin-left: auto; margin-right: auto; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.hidden { display: none !important; }

/* ---------------------------------------------------------
   十三、真机适配
   ---------------------------------------------------------
   装成 PWA 之后是独立应用，不需要桌面预览的假手机外壳。
   旧项目的 styles.css 里已经处理了 .statusbar / .homebar，
   这里只补 .phone 在窄屏下的行为。
   --------------------------------------------------------- */
@media (max-width: 460px) {
  .phone {
    max-width: none;
    border-radius: 0;
    box-shadow: none;
    min-height: 100dvh;
  }
}

@media (display-mode: standalone) {
  .phone {
    max-width: none;
    border-radius: 0;
    box-shadow: none;
  }
}
