/* ============================================================
   talk
   ============================================================ */

:root {
  --bg:        #0f1015;
  --surface:   #171923;
  --surface-2: #1f2230;
  --line:      #2a2e3f;
  --text:      #e7e9f0;
  --muted:     #8b90a4;
  --me:        #6c8cff;
  --you:       #f2845c;
  --danger:    #ff6b6b;
  --online:    #3ddc97;
  --away:      #e8b84b;

  --radius: 16px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI",
          "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

[hidden] { display: none !important; }

/* ---------- 進場畫面 ---------- */

.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(60rem 40rem at 20% -10%, #1c2140 0%, transparent 60%),
    radial-gradient(50rem 36rem at 110% 110%, #2a1f2e 0%, transparent 60%),
    var(--bg);
}

.gate-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 32px 26px 26px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .45);
}

.gate-title {
  margin: 0 0 24px;
  font-size: 24px;
  letter-spacing: .02em;
  text-align: center;
}

.gate-sub {
  margin: 0 0 26px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.7;
}

.field { display: block; margin-bottom: 18px; }

.field-label {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.input-key {
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: .08em;
  padding: 15px 14px;
}

.input-key::placeholder {
  font-size: 15px;
  font-weight: 400;
  letter-spacing: .04em;
  color: var(--muted);
}

.input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.input:focus {
  border-color: var(--me);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--me) 20%, transparent);
}

.btn-primary {
  width: 100%;
  padding: 14px;
  border: 0;
  border-radius: 13px;
  background: var(--me);
  color: #0b0d18;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: filter .15s, transform .1s;
}

.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-primary:active:not(:disabled) { transform: scale(.99); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.gate-error {
  margin: 0 0 14px;
  padding: 11px 13px;
  border-radius: 11px;
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  color: #ffb3b3;
  font-size: 13px;
  white-space: pre-line;
}

.remember {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

.remember input { accent-color: var(--me); cursor: pointer; }

/* ---------- 聊天畫面 ---------- */

.chat {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg);
}

.bar {
  flex: none;
  display: flex;
  align-items: center;
  /* 名稱隱藏時只剩按鈕，固定高度免得標題列忽高忽低 */
  min-height: 58px;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
}

.peer {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  padding: 4px 6px 4px 4px;
  margin: -4px -6px -4px -4px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .12s;
}

.peer[aria-expanded="true"] { background: var(--surface-2); }
.peer-caret { color: var(--muted); font-size: 11px; margin-left: 2px; }

.device-panel {
  flex: none;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  padding: 10px 16px 12px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  font-size: 13px;
  animation: rise .15s ease-out;
}

.device-row { display: contents; }

.device-k {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.device-v {
  color: var(--text);
  word-break: break-word;
  justify-self: end;
  text-align: right;
}

/* 推測出來的機型：講不死，所以視覺上也弱一階 */
.device-row.is-guess .device-v {
  color: var(--muted);
  font-style: italic;
}

.dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  transition: background .25s, box-shadow .25s;
}

.dot.is-online {
  background: var(--online);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--online) 22%, transparent);
}

/* 頁面還開著，但切到背景去了 */
.dot.is-online.is-away {
  background: var(--away);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--away) 22%, transparent);
}

.peer-text { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.peer-text strong { font-size: 15px; line-height: 1.3; }
.peer-text small { color: var(--muted); font-size: 12px; line-height: 1.4; }

.bar-actions { display: flex; gap: 4px; }

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 17px;
  line-height: 1;
  padding: 8px 9px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}

.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn[aria-pressed="false"] { opacity: .4; }

/* ---------- 訊息流 ---------- */

.stream {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.stream::-webkit-scrollbar { width: 8px; }
.stream::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 99px;
}

.stream-empty {
  margin: auto;
  color: var(--muted);
  font-size: 13.5px;
  text-align: center;
}

.day {
  align-self: center;
  margin: 16px 0 10px;
  padding: 4px 13px;
  border-radius: 99px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: .04em;
}

.msg {
  max-width: 78%;
  /* 長按選單期間才擋住系統的文字選取／放大鏡，平常仍可複製訊息 */
  -webkit-touch-callout: none;
  padding: 9px 14px;
  border-radius: var(--radius);
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  animation: pop .22s ease-out;
}

@keyframes pop {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .msg { animation: none; }
}

.msg.mine {
  align-self: flex-end;
  background: var(--me);
  color: #0b0d18;
  border-bottom-right-radius: 5px;
}

.msg.theirs {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}

/* 同一個人連續發言時收緊間距 */
.msg.run-mid, .msg.run-end { margin-top: -2px; }
.msg.mine.run-mid, .msg.mine.run-start { border-bottom-right-radius: 5px; }
.msg.mine.run-end  { border-top-right-radius: 5px; }
.msg.mine.run-mid  { border-top-right-radius: 5px; }
.msg.theirs.run-end { border-top-left-radius: 5px; }
.msg.theirs.run-mid { border-top-left-radius: 5px; }

/* 只有 emoji 的訊息放大顯示，泡泡退成透明 */
.msg.jumbo {
  font-size: 34px;
  line-height: 1.25;
  background: transparent;
  border: 0;
  padding: 2px 6px;
}

/* 收回後的泡泡：退成一行不搶眼的提示，但仍佔著原本的位置 */
.msg.recalled {
  background: transparent;
  border: 1px dashed var(--line);
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
  padding: 7px 12px;
  cursor: default;
}

.msg.recalled .msg-body { user-select: none; }

.msg a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

.stamp {
  margin: 2px 2px 8px;
  font-size: 11px;
  color: var(--muted);
}

.stamp.mine   { align-self: flex-end; }
.stamp.theirs { align-self: flex-start; }

.stamp .pending { opacity: .6; }
.stamp .failed  { color: var(--danger); }

/* ---------- 正在輸入 ---------- */

.typing {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 18px 6px;
  color: var(--muted);
  font-size: 12.5px;
  height: 22px;
}

.typing-dots { display: inline-flex; gap: 3px; }

.typing-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--you);
  animation: blink 1.2s infinite ease-in-out;
}

.typing-dots i:nth-child(2) { animation-delay: .16s; }
.typing-dots i:nth-child(3) { animation-delay: .32s; }

@keyframes blink {
  0%, 60%, 100% { opacity: .25; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-3px); }
}

/* ---------- 回覆引用 ---------- */

.quote {
  display: block;
  margin: 1px -5px 7px;
  padding: 6px 10px;
  border-left: 3px solid var(--quote, var(--me));
  border-radius: 4px 9px 9px 4px;
  background: color-mix(in srgb, var(--quote, var(--me)) 22%, transparent);
  font-size: 12.5px;
  line-height: 1.45;
  cursor: pointer;
  transition: background .14s;
}

.quote:hover {
  background: color-mix(in srgb, var(--quote, var(--me)) 34%, transparent);
}

/* 自己的泡泡是實色底，引用要用深色才看得出來 */
.msg.mine .quote {
  border-left-color: rgba(0, 0, 0, .45);
  background: rgba(0, 0, 0, .16);
}

.msg.mine .quote:hover { background: rgba(0, 0, 0, .24); }

.quote-who {
  display: block;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: .04em;
  line-height: 1.4;
  margin-bottom: 2px;
  color: var(--quote, var(--me));
}

.msg.mine .quote-who { color: rgba(0, 0, 0, .72); }

.quote-text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
  opacity: .85;
}

.msg-body { display: block; }

/* 跳到原訊息時閃一下 */
@keyframes flash {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  30%      { box-shadow: 0 0 0 3px color-mix(in srgb, var(--me) 55%, transparent); }
}

.msg.flash { animation: flash 1s ease-out; }

/* ---------- 反應 ---------- */

.reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: -1px 2px 4px;
}

.reactions.mine   { align-self: flex-end; }
.reactions.theirs { align-self: flex-start; }

.reaction {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  line-height: 1;
  padding: 3px 8px;
  border-radius: 99px;
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .1s;
}

.reaction:hover { border-color: #3c4157; }
.reaction:active { transform: scale(.92); }

.reaction.is-mine {
  border-color: var(--me);
  background: color-mix(in srgb, var(--me) 20%, var(--surface-2));
}

/* ---------- 動作選單 ---------- */

body.pressing .msg {
  -webkit-user-select: none;
  user-select: none;
}

.actions {
  position: fixed;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
  animation: rise .14s ease-out;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(4px) scale(.97); }
  to   { opacity: 1; transform: none; }
}

.reaction-row { display: flex; gap: 1px; }

.reaction-pick {
  appearance: none;
  border: 0;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  padding: 6px 7px;
  border-radius: 9px;
  cursor: pointer;
  transition: background .12s, transform .1s;
}

.reaction-pick:hover { background: var(--surface-2); transform: scale(1.15); }
.reaction-pick:active { transform: scale(.9); }

.act-btn {
  appearance: none;
  border: 0;
  border-left: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  white-space: nowrap;
  padding: 7px 11px 7px 12px;
  margin-left: 3px;
  border-radius: 0 9px 9px 0;
  cursor: pointer;
  transition: background .12s;
}

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

/* 反應列後面第一顆按鈕才需要那道分隔線，後面的彼此靠著就好 */
.act-btn + .act-btn {
  border-left: 0;
  margin-left: 0;
  border-radius: 9px;
  padding-left: 9px;
}

.act-danger { color: var(--danger); }
.act-danger:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); }

/* ---------- 回覆中提示列 ---------- */

.reply-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  animation: rise .15s ease-out;
}

.reply-bar-body {
  flex: 1;
  min-width: 0;
  border-left: 3px solid var(--quote, var(--me));
  border-radius: 3px;
  padding: 2px 0 2px 9px;
}

.reply-who {
  display: block;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .04em;
  color: var(--quote, var(--me));
  line-height: 1.4;
}

.reply-text {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-cancel {
  flex: none;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s, color .12s;
}

.reply-cancel:hover { background: var(--surface); color: var(--text); }

/* ---------- 表情符號 ---------- */

.quick {
  flex: none;
  display: flex;
  gap: 4px;
  padding: 0 14px 6px;
  overflow-x: auto;
  scrollbar-width: none;
}

.quick::-webkit-scrollbar { display: none; }

.quick-item {
  flex: none;
  appearance: none;
  border: 0;
  background: transparent;
  font-size: 21px;
  line-height: 1;
  padding: 5px 6px;
  border-radius: 9px;
  cursor: pointer;
  transition: background .12s, transform .1s;
}

.quick-item:hover { background: var(--surface-2); }
.quick-item:active { transform: scale(.88); }

.emoji-panel {
  flex: none;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.emoji-tabs {
  display: flex;
  gap: 2px;
  padding: 7px 12px 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.emoji-tabs::-webkit-scrollbar { display: none; }

.emoji-tab {
  flex: none;
  appearance: none;
  border: 0;
  background: transparent;
  font-size: 17px;
  line-height: 1;
  padding: 7px 11px;
  border-radius: 9px 9px 0 0;
  cursor: pointer;
  opacity: .45;
  border-bottom: 2px solid transparent;
  transition: opacity .15s, border-color .15s, background .15s;
}

.emoji-tab:hover { opacity: .8; background: var(--surface-2); }

.emoji-tab[aria-selected="true"] {
  opacity: 1;
  border-bottom-color: var(--me);
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: 2px;
  padding: 8px 10px 10px;
  max-height: 190px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.emoji-grid::-webkit-scrollbar { width: 8px; }
.emoji-grid::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 99px;
}

.emoji-item {
  appearance: none;
  border: 0;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  aspect-ratio: 1;
  border-radius: 9px;
  cursor: pointer;
  transition: background .12s, transform .1s;
}

.emoji-item:hover { background: var(--surface-2); }
.emoji-item:active { transform: scale(.85); }

.emoji-btn {
  flex: none;
  appearance: none;
  border: 0;
  background: transparent;
  font-size: 21px;
  line-height: 1;
  padding: 8px 4px 8px 0;
  cursor: pointer;
  opacity: .65;
  transition: opacity .15s, transform .1s;
}

.emoji-btn:hover { opacity: 1; }
.emoji-btn:active { transform: scale(.9); }
.emoji-btn[aria-expanded="true"] { opacity: 1; }

/* 照片按鈕：跟 emoji 鈕同一套視覺，額度用完時灰掉 */
.photo-btn {
  flex: none;
  appearance: none;
  border: 0;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  padding: 8px 6px;
  cursor: pointer;
  opacity: .65;
  transition: opacity .15s, transform .1s;
}

.photo-btn:hover { opacity: 1; }
.photo-btn:active { transform: scale(.9); }

.photo-btn:disabled,
.photo-btn.is-blocked {
  opacity: .25;
  cursor: not-allowed;
  filter: grayscale(1);
}

/* ---------- 照片訊息 ---------- */

/* 照片泡泡不需要內距，圖片自己就是內容 */
.msg.photo-msg {
  padding: 3px;
  max-width: min(72%, 320px);
}

.msg.photo-msg.has-photo { background: var(--surface-2); }

.photo {
  display: block;
  width: 100%;
  /* height:auto 會讓 width/height 屬性推不出比例，圖片載入前高度是 0，
     載入後才突然撐開——底部就被推走了。改用 aspect-ratio 先佔好位置。 */
  height: auto;
  aspect-ratio: var(--ratio, 4 / 3);
  max-height: 380px;
  object-fit: cover;
  border-radius: 13px;
  cursor: zoom-in;
  background: var(--surface);
}

/* 照片沒了之後退成一行提示，跟收回的樣子一致 */
.msg.photo-gone {
  padding: 7px 12px;
  background: transparent;
  border: 1px dashed var(--line);
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
  max-width: 78%;
}

/* ---------- 燈箱 ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, .88);
  animation: fade .15s ease-out;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  appearance: none;
  border: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .14);
  color: #fff;
  font-size: 17px;
  cursor: pointer;
}

.lightbox-close:hover { background: rgba(255, 255, 255, .24); }

/* ---------- 語音 ---------- */

.voice-btn {
  flex: none;
  appearance: none;
  border: 0;
  background: transparent;
  font-size: 19px;
  line-height: 1;
  padding: 8px 5px;
  cursor: pointer;
  opacity: .65;
  touch-action: none;          /* 按住錄音時不要把它當成捲動 */
  transition: opacity .15s, transform .1s;
}

.voice-btn:hover { opacity: 1; }
.voice-btn:active { transform: scale(.9); }

.voice-btn:disabled,
.voice-btn.is-blocked {
  opacity: .25;
  cursor: not-allowed;
  filter: grayscale(1);
}

/* 錄音中取代輸入列 */
.recording {
  flex: none;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 14px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  animation: rise .15s ease-out;
}

.rec-dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
  animation: rec-pulse 1.1s ease-in-out infinite;
}

@keyframes rec-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .25; }
}

.rec-time {
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  color: var(--text);
}

.rec-time.is-near { color: var(--away); }

.rec-hint {
  flex: 1;
  color: var(--muted);
  font-size: 12.5px;
}

.rec-cancel, .rec-stop {
  flex: none;
  appearance: none;
  border: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
}

.rec-cancel {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.rec-cancel:hover { color: var(--text); }

.rec-stop {
  background: var(--me);
  color: #0b0d18;
}

/* 語音泡泡 */
.msg.voice-msg { padding: 7px 11px; max-width: min(78%, 290px); }

.voice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 180px;
}

.voice-play {
  flex: none;
  appearance: none;
  border: 0;
  width: 31px;
  height: 31px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .16);
  color: inherit;
  font-size: 12px;
  cursor: pointer;
  line-height: 1;
}

.msg.theirs .voice-play { background: rgba(255, 255, 255, .09); }
.voice-play:hover { background: rgba(255, 255, 255, .26); }

.voice-track {
  flex: 1;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .2);
  cursor: pointer;
  position: relative;
}

.msg.theirs .voice-track { background: rgba(255, 255, 255, .12); }

.voice-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: currentColor;
  transition: width .1s linear;
}

.voice-time {
  flex: none;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  opacity: .75;
}

.msg.voice-gone {
  padding: 7px 12px;
  background: transparent;
  border: 1px dashed var(--line);
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
}

/* ---------- 用量 ---------- */

.usage-bar {
  flex: none;
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--line);
}

.usage-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  margin-bottom: 7px;
}

.usage-month { color: var(--muted); font-size: 11.5px; }

.usage-track {
  position: relative;
  height: 7px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.usage-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--online);
  transition: width .3s ease-out;
}

.usage-fill.is-hot { background: var(--danger); }

/* 熔斷門檻的刻度 */
.usage-mark {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  background: var(--muted);
  opacity: .5;
}

.usage-foot {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.usage-hot { color: var(--danger); }

.usage-note {
  margin: 7px 0 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--muted);
  opacity: .75;
}

/* ---------- 收回紀錄 ---------- */

.log-panel {
  flex: none;
  max-height: 42vh;
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  animation: rise .15s ease-out;
}

.log-head {
  flex: none;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 11px 16px 7px;
  font-size: 13px;
}

.log-count { color: var(--muted); font-size: 12px; }

.log-list {
  overflow-y: auto;
  padding: 0 16px 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.log-list::-webkit-scrollbar { width: 7px; }
.log-list::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 4px;
}

.log-empty {
  margin: 4px 0 8px;
  color: var(--muted);
  font-size: 12.5px;
}

.log-row {
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.log-row:first-child { border-top: 0; }

.log-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 3px;
  font-size: 11.5px;
  color: var(--muted);
}

.log-mode {
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  border: 1px solid currentColor;
}

.log-mode-recall { color: var(--away); }
.log-mode-remove { color: var(--danger); }

.log-who { color: var(--text); }
.log-when { margin-left: auto; }

.log-text {
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
  /* 原文可能很長，收在幾行內，需要細看再去資料庫查 */
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- 浮動提示 ---------- */

.toasts {
  position: fixed;
  left: 50%;
  bottom: 92px;
  z-index: 70;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: max-content;
  max-width: min(92vw, 420px);
}

.toast {
  pointer-events: auto;
  padding: 10px 16px;
  border-radius: 11px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.45;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 8px 26px rgba(0, 0, 0, .42);
  animation: toast-in .2s ease-out;
}

.toast-bad {
  border-color: color-mix(in srgb, var(--danger) 46%, var(--line));
  color: var(--danger);
}

.toast.is-leaving { animation: toast-out .18s ease-in forwards; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px) scale(.97); }
  to   { opacity: 1; transform: none; }
}

@keyframes toast-out {
  from { opacity: 1; transform: none; }
  to   { opacity: 0; transform: translateY(-6px) scale(.97); }
}

@media (prefers-reduced-motion: reduce) {
  .toast, .toast.is-leaving { animation: none; }
}

/* ---------- 確認框 ---------- */

.ask {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(6, 7, 12, .72);
  animation: fade .13s ease-out;
}

.ask-card {
  width: min(100%, 330px);
  padding: 20px 20px 16px;
  border-radius: 17px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 22px 60px rgba(0, 0, 0, .55);
  animation: rise .16s ease-out;
}

.ask-title {
  margin: 0 0 8px;
  font-size: 15.5px;
  font-weight: 600;
  line-height: 1.4;
}

.ask-body {
  margin: 0 0 18px;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--muted);
  word-break: break-word;
  /* 引用的訊息可能很長，收在幾行內就好 */
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ask-actions {
  display: flex;
  gap: 9px;
  justify-content: flex-end;
}

.ask-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  padding: 8px 16px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}

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

.ask-btn:focus-visible {
  outline: 2px solid var(--me);
  outline-offset: 2px;
}

.ask-yes {
  border-color: transparent;
  background: var(--me);
  color: #0b0d18;
  font-weight: 600;
}

.ask-yes:hover { background: color-mix(in srgb, var(--me) 88%, #fff); }

.ask-yes.is-danger {
  background: var(--danger);
  color: #1a0b0b;
}

.ask-yes.is-danger:hover { background: color-mix(in srgb, var(--danger) 88%, #fff); }

@media (prefers-reduced-motion: reduce) {
  .ask, .ask-card { animation: none; }
}

/* ---------- 拖曳提示 ---------- */

.drop-hint {
  position: fixed;
  inset: 12px;
  z-index: 55;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--me);
  border-radius: 18px;
  background: rgba(10, 12, 22, .82);
  color: var(--text);
  font-size: 15px;
  pointer-events: none;
}

/* ---------- 輸入列 ---------- */

.composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.composer-input {
  flex: 1;
  resize: none;
  max-height: 132px;
  padding: 11px 14px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  line-height: 1.5;
  outline: none;
  transition: border-color .15s;
}

.composer-input:focus { border-color: var(--me); }
.composer-input::placeholder { color: var(--muted); }

.send-btn {
  flex: none;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: var(--me);
  color: #0b0d18;
  font-size: 16px;
  cursor: pointer;
  transition: filter .15s, opacity .15s, transform .1s;
}

.send-btn:hover:not(:disabled) { filter: brightness(1.08); }
.send-btn:active:not(:disabled) { transform: scale(.93); }
.send-btn:disabled { opacity: .35; cursor: not-allowed; }

/* ---------- 手機 ---------- */

@media (max-width: 480px) {
  .msg { max-width: 85%; }
  .gate-card { padding: 28px 20px 22px; }
}
