/* —— 基础重置与排版 —— */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; max-width: 100%; }
body, h1, h2, h3, h4, p, ul, figure { margin: 0; }
body {
  background: var(--md-page-bg);
  color: var(--md-on-surface);
  font-family: var(--md-font);
  font-size: var(--md-body-size);
  line-height: var(--md-body-line);
  overflow: hidden;                 /* App 内部滚动，页面本身不滚 */
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-wrap: anywhere;          /* 文本节点一律可断行（契约 5.7） */
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
button {
  padding: 0; border: 0; background: none;
  cursor: pointer; text-align: inherit;
}
button:disabled, [aria-disabled="true"] { cursor: default; opacity: .5; }
ul { padding: 0; list-style: none; }
h1 { font-size: var(--md-display-size); line-height: var(--md-display-line); font-weight: 400; }
h2 { font-size: var(--md-title-size); line-height: var(--md-title-line); font-weight: 500; }
h3 { font-size: var(--md-body-size); line-height: var(--md-body-line); font-weight: 500; }
time, .badge, .call-timer { font-variant-numeric: tabular-nums; }
img { max-width: 100%; }

/* 图标：M3 用 currentColor 2px 描边、圆头圆角、24dp 光学尺寸 */
svg:not(.symbols) {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
svg.symbols, .symbols { position: absolute; width: 0; height: 0; overflow: hidden; pointer-events: none; }
svg { display: block; }

/* 焦点可见：3px primary 轮廓（契约 5.6） */
:where(a, button, input, textarea, select, [tabindex], [role="switch"]):focus-visible {
  outline: 3px solid var(--md-primary);
  outline-offset: 2px;
}
/* 「更换头像 / 附一张照片」这类 label 按钮：真 input 被 visually-hidden，焦点环画到 label 上 */
.file-button:has(+ input:focus-visible) {
  outline: 3px solid var(--md-primary);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

/* 状态层工具类：按压时叠一层 on-surface（不依赖 hover） */
.state-layer { position: relative; overflow: hidden; }
.state-layer::after {
  content: ""; position: absolute; inset: 0; z-index: 0;
  background: var(--md-state-press);
  opacity: 0; pointer-events: none;
  transition: opacity var(--md-dur) var(--md-ease);
}
.state-layer:active::after { opacity: 1; }

/* —— 外框与页面骨架 —— */
.frame {
  position: relative;
  width: 100%; max-width: 540px;
  height: 100vh; height: 100dvh;
  margin-inline: auto;
  display: flex; flex-direction: column;
  overflow: hidden;
  background: var(--md-surface);
  color: var(--md-on-surface);
}
.login, .home { flex: 1; min-height: 0; }
.home { height: 100%; display: flex; flex-direction: column; }

/* 页面容器：对话页 / 生活页 / 我的 三个 tab 面板 */
.tab, .screen { flex: 1; min-height: 0; }

/* —— 按钮：filled / tonal / text / danger（4 档） —— */
.primary, .secondary, .danger, .text-button, .file-button, .logout, .older {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--md-touch);
  padding: 0 24px;
  border: 1px solid transparent;
  border-radius: var(--md-shape-full);
  font-size: var(--md-body-size); line-height: var(--md-body-line); font-weight: 500;
  letter-spacing: .1px;
  background-image: none;
  transition: background-color var(--md-dur) var(--md-ease),
              border-color var(--md-dur) var(--md-ease),
              background-image var(--md-dur) var(--md-ease);
}
.primary svg, .secondary svg, .danger svg, .text-button svg, .file-button svg { width: 18px; height: 18px; }

/* 1) filled：主色实心 */
.primary { background-color: var(--md-primary); color: var(--md-on-primary); }
.primary:active { background-image: linear-gradient(var(--md-state-on-primary), var(--md-state-on-primary)); }

/* 2) tonal（secondary-container）：次行动作 */
.secondary, .file-button {
  background-color: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
}
.secondary:active, .file-button:active { background-image: linear-gradient(var(--md-state-on-container), var(--md-state-on-container)); }

/* 3) text：无底、主色文字（最低层级动作） */
.text-button {
  min-height: 40px; padding: 0 12px;
  border-radius: var(--md-shape-full);
  background-color: transparent;
  color: var(--md-primary);
  font-size: var(--md-body-size);
}
.text-button:active { background-image: linear-gradient(var(--md-state-press-strong), var(--md-state-press-strong)); }

/* 4) danger：destructive（挂断 / 删除） */
.danger { background-color: var(--md-error); color: var(--md-on-error); }
.danger:active { background-image: linear-gradient(var(--md-state-on-primary), var(--md-state-on-primary)); }

/* 文件选择按钮（label 承担按钮角色，真 input 隐藏） */
.file-button { cursor: pointer; user-select: none; }

/* 次要按钮的描边变体（`.secondary.outlined` 留给后续结构使用） */
.secondary.outlined {
  background-color: transparent;
  border-color: var(--md-outline);
  color: var(--md-primary);
}

.wide { width: 100%; }
.logout {
  width: 100%; margin-top: 24px;
  background-color: transparent;
  border-color: var(--md-outline-variant);
  color: var(--md-error);
}
.logout:active { background-image: linear-gradient(var(--md-state-press-strong), var(--md-state-press-strong)); }

/* 处理中：阻止重复触发并留反馈（契约 5.2） */
[data-loading="true"], [aria-busy="true"] { cursor: progress; opacity: .7; }
[data-loading="true"]::after, [aria-busy="true"]::after {
  content: ""; width: 14px; height: 14px; flex: none;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%;
  animation: md-spin .7s linear infinite;
}
@keyframes md-spin { to { transform: rotate(1turn); } }

/* —— 表单：M3 outlined 48px —— */
label:not(.file-button) {
  display: block;
  margin-bottom: 6px;
  color: var(--md-on-surface-variant);
  font-size: var(--md-label-size); line-height: var(--md-label-line);
  font-weight: 500; letter-spacing: .4px;
}
input:not([type=file]):not([type=checkbox]):not([type=radio]), textarea, select {
  width: 100%; min-width: 0;
  min-height: 48px;
  padding: 12px 16px;
  border: 1px solid var(--md-outline);
  border-radius: var(--md-shape-xs);
  background-color: transparent;
  color: var(--md-on-surface);
  font-size: var(--md-body-size); line-height: var(--md-body-line);
  letter-spacing: .2px;
  transition: border-color var(--md-dur) var(--md-ease),
              box-shadow var(--md-dur) var(--md-ease);
}
input:not([type=file]):hover, textarea:hover { border-color: var(--md-on-surface); }
input:not([type=file]):focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--md-primary);
  box-shadow: inset 0 0 0 1px var(--md-primary);
}
input::placeholder, textarea::placeholder { color: var(--md-on-surface-variant); opacity: 1; }
textarea { resize: none; }
input[type=file] { display: none; }

/* —— 图标按钮（48×48 触控区，40×40 视觉） —— */
.icon-button, .back-button {
  flex: none;
  width: var(--md-touch); height: var(--md-touch);
  display: grid; place-items: center;
  border-radius: 50%;
  background-color: transparent;
  border: 0;
  color: var(--md-on-surface-variant);
  transition: background-color var(--md-dur) var(--md-ease);
}
.icon-button:active, .back-button:active {
  background-image: linear-gradient(var(--md-state-press-strong), var(--md-state-press-strong));
}
.icon-button svg { width: 24px; height: 24px; }
.back-button { color: var(--md-on-surface); }
.back-button svg { width: 24px; height: 24px; transform: rotate(180deg); }

/* 通话类动作做成 filled tonal 图标按钮，和普通图标按钮拉开层级 */
.chat-head .icon-button {
  background-color: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
}

/* —— 头像（M3 tonal circle） —— */
.avatar {
  flex: none;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  overflow: hidden;
  border-radius: 50%;
  aspect-ratio: 1;
  background-color: var(--md-surface-container-highest);
  color: var(--md-on-surface-variant);
  font-size: var(--md-body-size); line-height: var(--md-body-line);
  font-weight: 500; letter-spacing: .02em;
  text-align: center;
}
.avatar img {
  width: 100%; height: 100%;
  object-fit: cover;
  opacity: var(--img-opacity);
  outline: var(--img-outline);
  outline-offset: -1px;
}
/* 对方 = 次色容器，我 = 主色容器（两个账号一眼分清） */
.avatar.peach { background-color: var(--md-secondary-container); color: var(--md-on-secondary-container); }
.avatar.mint { background-color: var(--md-primary-container); color: var(--md-on-primary-container); }
.avatar.small { width: 32px; height: 32px; font-size: var(--md-label-size); line-height: var(--md-label-line); }
.avatar.large { width: 56px; height: 56px; font-size: var(--md-headline-size); line-height: var(--md-headline-line); }

/* 顶部 App bar 已移除：进入首页直接是聊天；各 tab 自己承接顶部安全区（见 .chat-head / .scroll-tab）。 */

/* —— Navigation bar（80px，选中项 64×32 primary-container pill） —— */
.nav-bar, .tabs {
  flex: none;
  display: grid; grid-template-columns: repeat(3, 1fr);
  min-height: 80px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background-color: var(--md-surface-container);
  border-top: 0;
}
.nav-bar button, .tabs button {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  height: 100%; min-height: 64px;
  padding: 0 4px;
  background-color: transparent;
  color: var(--md-on-surface-variant);
  font-size: var(--md-label-size); line-height: var(--md-label-line);
  font-weight: 500; letter-spacing: .1px;
  transition: color var(--md-dur) var(--md-ease);
}
.nav-bar button::before, .tabs button::before {
  content: "";
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  width: 64px; height: 32px;
  border-radius: var(--md-shape-full);
  background-color: transparent;
  transition: background-color var(--md-dur-long) var(--md-ease);
}
.nav-bar button svg, .tabs button svg {
  position: relative; z-index: 1;
  width: 24px; height: 24px;
}
.nav-bar button span, .tabs button span {
  position: relative; z-index: 1;
  max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.nav-bar button[aria-current], .tabs button[aria-current] { color: var(--md-on-primary-container); }
.nav-bar button[aria-current]::before, .tabs button[aria-current]::before {
  background-color: var(--md-primary-container);
}
.nav-bar button:active::before, .tabs button:active::before {
  background-image: linear-gradient(var(--md-state-press-strong), var(--md-state-press-strong));
}

