/* =============================================================================
   组件层：按钮、输入、头像、会话行、消息、状态面板、对话框、Toast
   ========================================================================== */

/* ---------------------------------- 按钮 ---------------------------------- */
.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  --btn-line: var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--btn-line);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
  transition: background-color var(--dur-2) var(--ease-out), border-color var(--dur-2) var(--ease-out),
    color var(--dur-2) var(--ease-out), transform var(--dur-1) var(--ease-out),
    box-shadow var(--dur-2) var(--ease-out), opacity var(--dur-2) var(--ease-out);
}

.btn:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: var(--line-strong);
}

.btn:active:not(:disabled) {
  transform: translateY(1px) scale(0.995);
}

.btn:disabled {
  opacity: 0.45;
}

.btn--primary {
  --btn-bg: var(--accent);
  --btn-fg: var(--accent-ink);
  --btn-line: color-mix(in oklab, var(--accent) 80%, black);
  font-weight: 600;
}

.btn--primary:hover:not(:disabled) {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  box-shadow: 0 8px 24px -14px var(--accent);
}

.btn--ghost {
  --btn-bg: transparent;
  --btn-line: transparent;
  --btn-fg: var(--text-mute);
}

.btn--ghost:hover:not(:disabled) {
  --btn-fg: var(--text);
  background: var(--surface-2);
  border-color: var(--line-soft);
}

.btn--danger {
  --btn-fg: var(--danger);
  --btn-bg: var(--danger-soft);
  --btn-line: color-mix(in oklab, var(--danger) 26%, transparent);
}

.btn--danger:hover:not(:disabled) {
  background: color-mix(in oklab, var(--danger) 18%, transparent);
  border-color: color-mix(in oklab, var(--danger) 40%, transparent);
}

.btn--block {
  width: 100%;
  height: 40px;
}

.btn--sm {
  height: 30px;
  padding: 0 10px;
  font-size: var(--text-xs);
}

.btn--icon {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: var(--r-sm);
}

.btn__spin {
  animation: spin 900ms linear infinite;
}

.btn.is-busy {
  pointer-events: none;
}

/* ---------------------------------- 输入 ---------------------------------- */
.field {
  display: grid;
  gap: 6px;
}

.field__label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--text-mute);
}

.input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--text-md);
  transition: border-color var(--dur-2) var(--ease-out), box-shadow var(--dur-2) var(--ease-out),
    background-color var(--dur-2) var(--ease-out);
}

.input::placeholder {
  color: var(--text-mute);
}

.input:hover {
  border-color: var(--line-strong);
}

.input:focus {
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
  outline: none;
}

.input[aria-invalid="true"] {
  border-color: color-mix(in oklab, var(--danger) 60%, var(--line));
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.input--mono {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.search {
  position: relative;
  display: flex;
  align-items: center;
}

.search svg {
  position: absolute;
  left: 10px;
  color: var(--text-mute);
  pointer-events: none;
  transition: color var(--dur-2) var(--ease-out);
}

.search:focus-within svg {
  color: var(--accent);
}

.search .input {
  height: 34px;
  padding-left: 32px;
  font-size: var(--text-sm);
  background: var(--surface-2);
}

/* 复选框 */
.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  padding-top: 2px;
}

.checkbox input {
  appearance: none;
  width: 16px;
  height: 16px;
  margin: 0;
  border-radius: 4px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  cursor: pointer;
  display: grid;
  place-content: center;
  transition: background-color var(--dur-2) var(--ease-out), border-color var(--dur-2) var(--ease-out);
}

.checkbox input::after {
  content: "";
  width: 8px;
  height: 4px;
  border-left: 1.8px solid var(--accent-ink);
  border-bottom: 1.8px solid var(--accent-ink);
  transform: rotate(-45deg) scale(0);
  transform-origin: center;
  transition: transform var(--dur-2) var(--ease-spring);
  margin-top: -2px;
}

.checkbox input:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.checkbox input:checked::after {
  transform: rotate(-45deg) scale(1);
}

/* 开关 */
.switch {
  position: relative;
  width: 38px;
  height: 22px;
  flex: none;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  border: 1px solid var(--line);
  transition: background-color var(--dur-3) var(--ease-out), border-color var(--dur-3) var(--ease-out);
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-mute);
  transition: transform var(--dur-3) var(--ease-spring), background-color var(--dur-3) var(--ease-out);
}

.switch[aria-checked="true"] {
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

.switch[aria-checked="true"]::after {
  transform: translateX(16px);
  background: var(--accent);
}

/* ---------------------------------- 头像 ---------------------------------- */
.avatar {
  --av-a: #4a5a3a;
  --av-b: #2a3324;
  position: relative;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  overflow: hidden;
  background:
    radial-gradient(120% 120% at 22% 18%, color-mix(in oklab, var(--av-a) 92%, white 12%), var(--av-b));
  color: #f2f5ea;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  user-select: none;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

/* 有图片时隐藏渐变回退与鸟喙折角；图片加载失败由 JS 移除 .avatar--image */
.avatar--image::after {
  display: none;
}

.avatar__fallback {
  display: grid;
  place-items: center;
  position: absolute;
  inset: 0;
}

.avatar--image .avatar__fallback {
  visibility: hidden;
}

.avatar__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* 可戳头像：双击 / 右键；动画只改 transform，不影响布局 */
.poke-target {
  cursor: pointer;
}

.poke-target.is-poked,
.avatar.is-poked {
  animation: poke-shake 620ms var(--ease-out);
}

@keyframes poke-shake {
  0%, 100% { transform: rotate(0deg) scale(1); }
  18% { transform: rotate(-9deg) scale(1.06); }
  36% { transform: rotate(8deg) scale(1.06); }
  54% { transform: rotate(-5deg) scale(1.03); }
  72% { transform: rotate(3deg) scale(1.01); }
}

.poke-menu {
  position: fixed;
  z-index: 90;
  min-width: 148px;
  padding: 5px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--line);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.34);
  animation: menu-in 140ms var(--ease-out);
}

.poke-menu__item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 9px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: var(--fs-sm);
  text-align: left;
  cursor: pointer;
}

.poke-menu__item:hover,
.poke-menu__item:focus-visible {
  background: var(--surface-3);
  outline: none;
}

@keyframes menu-in {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* 头像上的「鸟喙」折角，替代默认圆形色块 */
.avatar::after {
  content: "";
  position: absolute;
  right: -9px;
  top: -9px;
  width: 22px;
  height: 22px;
  background: color-mix(in oklab, var(--av-a) 60%, white 40%);
  transform: rotate(45deg);
  opacity: 0.16;
}

.avatar--sm {
  width: 32px;
  height: 32px;
  font-size: 13px;
}

.avatar--md {
  width: 44px;
  height: 44px;
  font-size: 17px;
}

.avatar--lg {
  width: 72px;
  height: 72px;
  font-size: 27px;
}

.avatar--self {
  width: 38px;
  height: 38px;
  font-size: 15px;
}

/* 系统/说明会话：不参与哈希配色，直接用品牌苔绿，避免出现奇怪的撞色头像 */
.avatar--system {
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent-line);
}

.avatar--system::after {
  background: var(--accent);
  opacity: 0.12;
}

/* 头像右下角的状态徽标 */
.presence-badge {
  position: absolute;
  right: -2px;
  bottom: -2px;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  color: var(--text-mute);
  transition: color var(--dur-3) var(--ease-out), border-color var(--dur-3) var(--ease-out),
    background-color var(--dur-3) var(--ease-out);
}

.presence-badge[data-state="online"] {
  color: var(--state-online);
  border-color: color-mix(in oklab, var(--state-online) 42%, var(--line));
}

.presence-badge[data-state="away"] {
  color: var(--state-away);
  border-color: color-mix(in oklab, var(--state-away) 38%, var(--line));
}

.presence-badge[data-state="busy"] {
  color: var(--state-busy);
  border-color: color-mix(in oklab, var(--state-busy) 38%, var(--line));
}

.presence-badge[data-state="dnd"] {
  color: var(--state-dnd);
  border-color: color-mix(in oklab, var(--state-dnd) 38%, var(--line));
}

.presence-badge[data-state="offline"],
.presence-badge[data-state="invisible"] {
  color: var(--state-offline);
}

.presence-badge__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 7px color-mix(in oklab, currentColor 55%, transparent);
}

.presence-badge__ring {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
}

.presence-badge[data-state="invisible"] .presence-badge__ring {
  border-style: dashed;
}

/* 文本行里的状态符号（黄月 / 红减号 / 铃铛） */
.state-glyph {
  display: inline-flex;
  align-items: center;
  color: var(--text-mute);
}

.state-glyph[data-state="away"] {
  color: var(--state-away);
}

.state-glyph[data-state="busy"] {
  color: var(--state-busy);
}

.state-glyph[data-state="dnd"] {
  color: var(--state-dnd);
}

.avatar__kind {
  position: absolute;
  right: -2px;
  bottom: -2px;
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text-dim);
}

.avatar__kind svg {
  width: 9px;
  height: 9px;
}

/* --------------------------------- 会话行 --------------------------------- */
.session {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  padding: 9px 10px;
  border-radius: var(--r-md);
  text-align: left;
  color: var(--text);
  transition: background-color var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-out);
}

.session:hover {
  background: var(--surface-2);
}

.session:active {
  transform: scale(0.992);
}

.session.is-active {
  background: color-mix(in oklab, var(--accent) 9%, var(--surface-2));
}

.session.is-active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 2.5px;
  height: 20px;
  border-radius: var(--r-pill);
  background: var(--accent);
  transform: translateY(-50%);
}

.session__avatar {
  position: relative;
}

.session__avatar .presence-badge {
  position: absolute;
  right: -2px;
  bottom: -2px;
  box-shadow: 0 0 0 2.5px var(--surface);
}

.session.is-active .session__avatar .presence-badge {
  box-shadow: 0 0 0 2.5px color-mix(in oklab, var(--accent) 9%, var(--surface-2));
}

.session__body {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 1px;
}

.session__top {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.session__name {
  flex: 1;
  min-width: 0;
  font-size: var(--text-md);
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session__time {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--text-mute);
  flex: none;
}

.session__preview {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  color: var(--text-mute);
  font-size: var(--text-xs);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session.is-active .session__preview,
.session:hover .session__preview {
  color: var(--text-dim);
}

.session__preview .prefix {
  color: var(--text-mute);
  font-size: var(--text-2xs);
}

.session__unread {
  display: grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  flex: none;
  border-radius: var(--r-pill);
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: 700;
  animation: badge-pop var(--dur-3) var(--ease-spring);
}

.session__muted {
  color: var(--text-mute);
}

.sessions__empty {
  display: grid;
  gap: var(--sp-2);
  place-items: center;
  padding: var(--sp-8) var(--sp-4);
  text-align: center;
  color: var(--text-mute);
  font-size: var(--text-xs);
  line-height: 1.7;
}

/* --------------------------------- 消息 ---------------------------------- */
.msg {
  display: flex;
  /* 头像对齐气泡顶部（而不是底部 meta），更像「人站在消息旁边」 */
  align-items: flex-start;
  gap: 9px;
  margin-top: 10px;
  animation: msg-in var(--dur-4) var(--ease-out) both;
}

.msg--in {
  justify-content: flex-start;
}

.msg--out {
  justify-content: flex-end;
}

.msg--grouped {
  margin-top: 2px;
}

.msg__avatar-slot {
  width: 28px;
  flex: none;
}

.msg__avatar-slot .avatar {
  border-radius: 50%;
}

.msg__stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  min-width: 0;
  max-width: min(76%, 560px);
}

.msg--out .msg__stack {
  align-items: flex-end;
}

.msg__bubble {
  position: relative;
  padding: 8px 12px;
  border-radius: var(--r-bubble) var(--r-bubble) var(--r-bubble) var(--r-bubble-tail);
  background: var(--bubble-in);
  border: 1px solid var(--bubble-in-line);
  color: var(--text);
  font-size: var(--text-md);
  line-height: 1.62;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  transition: border-color var(--dur-2) var(--ease-out), background-color var(--dur-2) var(--ease-out);
}

.msg--in .msg__bubble:hover {
  border-color: var(--line-strong);
}

.msg--out .msg__bubble {
  border-radius: var(--r-bubble) var(--r-bubble) var(--r-bubble-tail) var(--r-bubble);
  background: var(--bubble-out);
  border-color: var(--bubble-out-line);
}

.msg__meta {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 2px;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--text-mute);
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-out);
}

.msg:hover .msg__meta,
.msg:focus-within .msg__meta,
.msg--tail .msg__meta {
  opacity: 1;
  transform: none;
}

.msg--tail .msg__meta {
  color: var(--text-mute);
}

.msg__status {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.msg__status[data-status="sending"] {
  color: var(--text-mute);
}

.msg__status[data-status="failed"] {
  color: var(--danger);
}

.msg__status[data-status="delivered"] {
  color: var(--accent);
}

.msg__copy {
  display: grid;
  place-items: center;
  width: 18px;
  height: 16px;
  border-radius: 4px;
  color: var(--text-mute);
  opacity: 0;
  transition: opacity var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out),
    background-color var(--dur-1) var(--ease-out);
}

.msg:hover .msg__copy,
.msg:focus-within .msg__copy {
  opacity: 1;
}

.msg__copy:hover {
  color: var(--text);
  background: var(--surface-3);
}

.msg__retry {
  color: var(--danger);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.msg--pending .msg__bubble {
  animation: pending-breathe 1.8s var(--ease-in-out) infinite;
}

.msg__system {
  align-self: center;
  max-width: 82%;
  margin: var(--sp-2) auto;
  padding: 7px 12px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px dashed var(--line);
  color: var(--text-mute);
  font-size: var(--text-xs);
  line-height: 1.65;
  text-align: center;
}

/* 输入中/同步中提示 */
.presence-typing {
  display: inline-flex;
  gap: 3px;
  align-items: center;
}

.presence-typing i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  animation: typing 1.2s var(--ease-in-out) infinite;
}

.presence-typing i:nth-child(2) {
  animation-delay: 0.16s;
}

.presence-typing i:nth-child(3) {
  animation-delay: 0.32s;
}

/* ------------------------------- 状态面板 --------------------------------- */
.pm {
  position: fixed;
  z-index: var(--z-popover);
  width: min(340px, calc(100vw - 20px));
  padding: var(--sp-3);
  border-radius: var(--r-xl);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-pop);
  transform-origin: bottom left;
  animation: pop-in var(--dur-3) var(--ease-spring) both;
}

.pm[data-exiting="true"] {
  animation: pop-out var(--dur-2) var(--ease-out) both;
}

.pm__head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-1) var(--sp-1) var(--sp-3);
}

.pm__head-text {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.pm__head-name {
  font-size: var(--text-md);
  font-weight: 600;
}

.pm__head-sub {
  font-size: var(--text-xs);
  color: var(--text-mute);
}

.pm__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.pm__opt {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 9px 10px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: var(--text-sm);
  text-align: left;
  transition: background-color var(--dur-2) var(--ease-out), border-color var(--dur-2) var(--ease-out),
    color var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-spring);
}

.pm__opt:hover {
  background: var(--surface-3);
  color: var(--text);
  transform: translateY(-1px);
}

.pm__opt[aria-checked="true"] {
  color: var(--text);
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

.pm__opt-icon {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex: none;
  color: var(--text-mute);
  background: var(--surface);
  border: 1px solid var(--line-soft);
  transition: color var(--dur-2) var(--ease-out), background-color var(--dur-2) var(--ease-out);
}

.pm__opt[data-state="online"] .pm__opt-icon {
  color: var(--state-online);
}

.pm__opt[data-state="away"] .pm__opt-icon {
  color: var(--state-away);
}

.pm__opt[data-state="busy"] .pm__opt-icon {
  color: var(--state-busy);
}

.pm__opt[data-state="dnd"] .pm__opt-icon {
  color: var(--state-dnd);
}

.pm__opt[data-state="invisible"] .pm__opt-icon {
  color: var(--state-invisible);
}

.pm__opt-check {
  margin-left: auto;
  color: var(--accent);
  animation: check-in var(--dur-3) var(--ease-spring);
}

.pm__sep {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin: var(--sp-3) 2px var(--sp-2);
  font-size: var(--text-2xs);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-mute);
}

.pm__sep::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line-soft);
}

.pm__custom {
  display: flex;
  gap: 6px;
}

.pm__custom .input {
  height: 34px;
  font-size: var(--text-sm);
}

.pm__emoji {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 3px;
  margin-top: 6px;
}

.pm__emoji button {
  display: grid;
  place-items: center;
  height: 32px;
  border-radius: var(--r-xs);
  font-size: 16px;
  line-height: 1;
  border: 1px solid transparent;
  opacity: 0.72;
  transition: background-color var(--dur-2) var(--ease-out), opacity var(--dur-2) var(--ease-out),
    transform var(--dur-2) var(--ease-spring), border-color var(--dur-2) var(--ease-out);
}

.pm__emoji button:hover {
  background: var(--surface-2);
  opacity: 1;
  transform: translateY(-1px) scale(1.08);
}

.pm__emoji button[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  opacity: 1;
}

.pm__note {
  display: flex;
  gap: 6px;
  margin-top: var(--sp-3);
  padding: 8px 9px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text-mute);
  font-size: var(--text-2xs);
  line-height: 1.6;
}

.pm__note svg {
  color: var(--accent);
  margin-top: 1px;
}

/* -------------------------------- 对话框 ---------------------------------- */
.dialog {
  position: fixed;
  inset: 0;
  z-index: var(--z-dialog);
  display: grid;
  place-items: center;
  padding: var(--sp-4);
}

.dialog__backdrop {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  backdrop-filter: blur(3px);
  animation: fade-in var(--dur-3) var(--ease-out) both;
}

.dialog__panel {
  position: relative;
  width: min(430px, 100%);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  padding: var(--sp-5);
  border-radius: var(--r-xl);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-pop);
  animation: dialog-in var(--dur-4) var(--ease-spring) both;
}

.dialog[data-exiting="true"] .dialog__panel {
  animation: dialog-out var(--dur-2) var(--ease-out) both;
}

.dialog[data-exiting="true"] .dialog__backdrop {
  animation: fade-out var(--dur-2) var(--ease-out) both;
}

.dialog__title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 500;
}

.dialog__desc {
  margin-top: var(--sp-1);
  color: var(--text-mute);
  font-size: var(--text-sm);
  line-height: 1.65;
}

.dialog__body {
  display: grid;
  gap: var(--sp-3);
  margin-top: var(--sp-4);
}

.dialog__foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  margin-top: var(--sp-5);
}

/* --------------------------------- Toast --------------------------------- */
.toasts {
  position: fixed;
  z-index: var(--z-toast);
  right: var(--sp-4);
  /* 放右上角：底部是输入区与发送键，通知不能盖住它 */
  top: calc(var(--header-h) + var(--sp-3));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--sp-2);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  max-width: min(360px, calc(100vw - 32px));
  padding: 10px 12px;
  border-radius: var(--r-md);
  background: var(--surface-translucent);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-2);
  backdrop-filter: blur(14px);
  font-size: var(--text-xs);
  line-height: 1.6;
  color: var(--text-dim);
  pointer-events: auto;
  animation: toast-in var(--dur-4) var(--ease-spring) both;
}

.toast[data-exiting="true"] {
  animation: toast-out var(--dur-2) var(--ease-out) both;
}

.toast__icon {
  margin-top: 1px;
  flex: none;
}

.toast[data-tone="ok"] .toast__icon {
  color: var(--ok);
}

.toast[data-tone="warn"] .toast__icon {
  color: var(--warn);
}

.toast[data-tone="danger"] .toast__icon {
  color: var(--danger);
}

.toast[data-tone="info"] .toast__icon {
  color: var(--accent);
}

.toast__title {
  color: var(--text);
  font-weight: 550;
}

.toast__content {
  min-width: 0;
}

.toast__body {
  color: var(--text-mute);
}

/* ---------------------------------- 杂项 ---------------------------------- */
.kbd {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 5px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--text-dim);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  font-size: var(--text-2xs);
  color: var(--text-dim);
}

.badge--accent {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent);
}

.badge--danger {
  background: var(--danger-soft);
  border-color: color-mix(in oklab, var(--danger) 26%, transparent);
  color: var(--danger);
}

.id-box {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.id-box code {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-dim);
  padding: 4px 7px;
  border-radius: var(--r-xs);
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 240px;
}

.theme-choice {
  display: flex;
  gap: 8px;
}

.theme-choice__opt {
  display: grid;
  gap: 6px;
  justify-items: center;
  padding: 10px 12px;
  width: 84px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-mute);
  font-size: var(--text-xs);
  transition: border-color var(--dur-2) var(--ease-out), color var(--dur-2) var(--ease-out),
    background-color var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-spring);
}

.theme-choice__opt:hover {
  transform: translateY(-1px);
  color: var(--text);
}

.theme-choice__opt[aria-checked="true"] {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--text);
}

.theme-choice__swatch {
  width: 34px;
  height: 22px;
  border-radius: var(--r-xs);
  border: 1px solid var(--line);
}

.theme-choice__swatch[data-swatch="dark"] {
  background: linear-gradient(135deg, #0a0b0c 0 50%, #171b1f 50% 100%);
}

.theme-choice__swatch[data-swatch="light"] {
  background: linear-gradient(135deg, #f3f2ec 0 50%, #ffffff 50% 100%);
}

.theme-choice__swatch[data-swatch="system"] {
  background: linear-gradient(135deg, #0a0b0c 0 50%, #f3f2ec 50% 100%);
}

/* 头像选择器里的小圆点 + 状态文字 */
.presence-line {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: var(--text-xs);
  color: var(--text-mute);
}

/* 断线时的输入区遮罩提示 */
.offline-hint {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--warn);
  font-size: var(--text-2xs);
}

/* ------------------------------ 收尾细节补充 ------------------------------ */

.sidebar__foot-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar__foot-text[data-state="online"] {
  color: var(--text-dim);
}

.sidebar__foot-hint {
  flex: none;
  color: var(--text-mute);
  opacity: 0.75;
}

.session__avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chat__header .session__avatar .presence-badge {
  box-shadow: 0 0 0 2.5px var(--bg);
}

.chat__peer-state-text {
  white-space: nowrap;
}

.msg__avatar-slot {
  width: 32px;
}

.net-bar[data-tone="info"] {
  color: var(--text-dim);
}

.pm {
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.composer.is-disabled .composer__box {
  opacity: 0.72;
}

.composer.is-disabled .composer__input {
  cursor: not-allowed;
}

/* 设置页里的主题卡片在窄屏换行 */
@media (max-width: 600px) {
  .settings__row {
    flex-wrap: wrap;
  }

  .settings__row .theme-choice {
    width: 100%;
  }

  .theme-choice__opt {
    flex: 1;
    width: auto;
  }

  .id-box code {
    max-width: 150px;
  }
}

/* 5 个状态让最后一格占满整行，避免右下角留空 */
.pm__opt:last-child {
  grid-column: span 2;
}

/* --------------------------- 手机：面板形态切换 --------------------------- */
@media (max-width: 640px) {
  /* 对话框变成底部抽屉 */
  .dialog {
    align-items: flex-end;
    padding: 0;
  }

  .dialog__panel {
    width: 100%;
    max-height: 88dvh;
    padding: var(--sp-5) var(--sp-4) calc(var(--sp-5) + env(safe-area-inset-bottom, 0px));
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    animation-name: sheet-up;
  }

  .dialog[data-exiting="true"] .dialog__panel {
    animation-name: sheet-down;
  }

  /* 状态面板从头像旁的小卡片变成悬浮动作面板 */
  .pm {
    max-height: 72dvh;
    animation-name: sheet-in;
  }

  .pm[data-exiting="true"] {
    animation-name: sheet-out;
  }

  .pm__grid {
    gap: 6px;
  }

  .pm__opt {
    padding: 11px 10px;
  }

  .pm__emoji button {
    height: 38px;
    font-size: 18px;
  }
}