/* ================================================================
   style.css – VoiceTranslate v4
   Tiếng Việt : Be Vietnam Pro (Google Fonts)
   Tiếng Trung  : Ma Shan Zheng (Google Fonts – Khải Thư)
   ================================================================ */

/* ── Tokens ── */
:root {
  --bg:         #0d0d21;
  --bg-header:  rgba(13,13,33,.92);
  --bg-bottom:  rgba(13,13,33,.96);
  --bg-bubble:  #1a1a38;
  --border:     rgba(255,255,255,.08);

  --vi:         #f59e0b;   /* amber  – người Việt */
  --vi-light:   rgba(245,158,11,.14);
  --vi-ring:    rgba(245,158,11,.35);

  --zh:         #ef4444;   /* red    – người Trung */
  --zh-light:   rgba(239,68,68,.14);
  --zh-ring:    rgba(239,68,68,.35);

  --tr:         rgba(255,255,255,.38);  /* màu chữ bản dịch */

  --purple:     #7c3aed;
  --cyan:       #06b6d4;

  --t1: #f1f5f9;
  --t2: #94a3b8;
  --t3: #475569;

  --header-h: 54px;
  --bottom-h: 82px;

  /* Font scale (changed by JS) */
  --fs-bubble: 15px;
  --fs-zh:     17px;

  --ease:   cubic-bezier(.4,0,.2,1);
  --spring: cubic-bezier(.34,1.56,.64,1);
  --keyboard-h: 0px; /* JS cập nhật khi bàn phím ảo hiện */
}

/* ── Reset ── */
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
html{-webkit-text-size-adjust:100%}

body {
  font-family: 'Be Vietnam Pro', system-ui, sans-serif;
  background: var(--bg);
  color: var(--t1);
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  overflow: hidden;
}

/* Ambient glow */
body::before {
  content:''; position:fixed; inset:0; pointer-events:none; z-index:0;
  background:
    radial-gradient(ellipse 60% 50% at 20% 10%, rgba(124,58,237,.12), transparent),
    radial-gradient(ellipse 50% 40% at 80% 90%, rgba(6,182,212,.08), transparent);
}

/* ================================================================
   HEADER
================================================================ */
.header {
  position: relative; z-index: 20;
  /* height tự điều chỉnh theo safe area (Dynamic Island / notch) */
  min-height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: 0 14px;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: 8px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  flex-shrink: 0;
  box-sizing: border-box;
}

.header-left { display:flex; align-items:center; gap:8px; }
.logo-icon   { flex-shrink:0; }
.header-title {
  font-size:15px; font-weight:700; letter-spacing:-.2px;
  background: linear-gradient(130deg, #a78bfa, var(--cyan));
  -webkit-background-clip:text; -webkit-text-fill-color:transparent;
  background-clip:text;
}

.header-right { display:flex; align-items:center; gap:8px; }

/* Status chip */
.status-chip {
  display:flex; align-items:center; gap:5px;
  padding:4px 10px;
  background:rgba(255,255,255,.05);
  border:1px solid var(--border);
  border-radius:100px;
  font-size:11px; font-weight:500; color:var(--t2);
}
.sdot {
  width:6px; height:6px; border-radius:50%;
  background:#10b981;
  box-shadow:0 0 6px rgba(16,185,129,.7);
  transition:.3s var(--ease);
}
.sdot.busy  { background:var(--purple); box-shadow:0 0 8px rgba(124,58,237,.7); animation:blink 1s infinite; }
.sdot.error { background:#ef4444; }
@keyframes blink{0%,100%{opacity:1}50%{opacity:.25}}

/* Install button – luôn hiển, chỉ ẩn sau khi đã cài xong */
.install-btn {
  display:flex; align-items:center; gap:5px;
  padding:5px 12px;
  background:linear-gradient(135deg,var(--purple),#8b5cf6);
  border:none; border-radius:100px;
  color:#fff; font-family:inherit; font-size:12px; font-weight:600;
  cursor:pointer;
  box-shadow:0 3px 14px rgba(124,58,237,.4);
  transition:.25s var(--ease);
}
.install-btn.hidden { display:none; }
.install-btn:hover{transform:translateY(-1px);box-shadow:0 5px 20px rgba(124,58,237,.55)}

/* Font size picker */
.font-picker {
  display:flex; align-items:center;
  background:rgba(255,255,255,.05);
  border:1px solid var(--border);
  border-radius:8px;
  overflow:hidden;
  flex-shrink:0;
}
.fp-btn {
  width:26px; height:28px;
  background:transparent; border:none;
  color:var(--t3); font-family:inherit;
  font-size:11px; font-weight:700;
  cursor:pointer; transition:.2s var(--ease);
}
.fp-btn:hover  { color:var(--t1); background:rgba(255,255,255,.07); }
.fp-btn.active { background:var(--purple); color:#fff; }

/* TTS button – sáng lên khi bật */
.tts-btn { transition:.2s var(--ease); }
.tts-btn.on {
  border-color:rgba(16,185,129,.5);
  color:#10b981;
  background:rgba(16,185,129,.1);
}

/* Mic icon wrapper – để swap được */
.mic-icon {
  display:flex; align-items:center; justify-content:center;
  width:100%; height:100%;
  position:relative; z-index:1;
}
.mic-icon svg { width:22px; height:22px; color:#fff; }

/* Stop icon hiện khi active */
.mic-btn.active .mic-icon svg { display:none; }
.mic-btn.active .mic-icon::after {
  content:'';
  display:block;
  width:18px; height:18px;
  background:#fff;
  border-radius:4px;
  box-shadow:0 1px 4px rgba(0,0,0,.3);
}

/* ── Font size scales ── */
body.font-sm { --fs-bubble:13px; --fs-zh:15px; }
body.font-md { --fs-bubble:15px; --fs-zh:17px; }
body.font-lg { --fs-bubble:18px; --fs-zh:21px; }

/* ================================================================
   CHAT STREAM
================================================================ */
.chat-stream {
  position:relative; z-index:1;
  flex:1; min-height:0;
  overflow-y:auto; overflow-x:hidden;
  padding:14px 12px 10px;
  display:flex; flex-direction:column; gap:4px;
  -webkit-overflow-scrolling:touch;
  scroll-behavior:smooth;
}

/* scrollbar */
.chat-stream::-webkit-scrollbar{width:3px}
.edit-textarea::-webkit-scrollbar-thumb { background: rgba(124,58,237,.3); border-radius: 10px; }

/* ================================================================
   TEXT INPUT PANEL
================================================================ */
#ti-overlay {
  position: fixed; inset: 0; z-index: 400;
  background: rgba(0,0,0,.6); backdrop-filter: blur(3px);
  opacity: 0; pointer-events: none; transition: .3s var(--ease);
}
#ti-overlay.open { opacity: 1; pointer-events: auto; }

#text-input-panel {
  position: fixed;
  bottom: var(--keyboard-h);
  left: 0; right: 0; z-index: 401;
  background: #111128;
  border-top: 1px solid var(--border);
  /* Giới hạn chiều cao – không phình vượt khỏi màn hình */
  max-height: 70vh;
  max-height: 70dvh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  transform: translateY(100%);
  transition: transform .35s var(--ease), bottom .15s var(--ease);
  box-shadow: 0 -8px 40px rgba(0,0,0,.5);
}
#text-input-panel.open { transform: translateY(0); }

#text-input-panel .panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}
#text-input-panel .panel-title { font-size: 15px; font-weight: 700; color: var(--t1); margin: 0; }
#text-input-panel .panel-body { padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
#text-input-panel .edit-textarea {
  width: 100%;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--t1);
  padding: 12px;
  font-size: 16px;  /* BẮT BUỘC >= 16px – ngăn iOS Safari tự zoom khi focus */
  line-height: 1.5;
  resize: none;
  -webkit-appearance: none; /* loại bỏ style iOS mặc định */
}
#text-input-panel .edit-textarea:focus {
  outline: none;
  border-color: var(--purple);
  box-shadow: 0 0 0 2px rgba(124,58,237,.2);
}
.ti-send-btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: .2s var(--ease);
}
.ti-send-btn:active { transform: scale(0.95); opacity: 0.8; }


/* ── Nhãn ngày / bắt đầu ── */
.day-label {
  text-align:center;
  font-size:11px; font-weight:500; color:var(--t3);
  padding:4px 12px;
  background:rgba(255,255,255,.04);
  border:1px solid var(--border);
  border-radius:100px;
  align-self:center;
  margin-bottom:6px;
}

/* ================================================================
   MESSAGE GROUP
   Mỗi lượt nói = 1 group chứa bubble gốc + bubble dịch
================================================================ */
.msg-group {
  display:flex; flex-direction:column;
  gap:3px;
  max-width:82%;
  animation:msgIn .35s var(--spring) both;
}
@keyframes msgIn{from{opacity:0;transform:translateY(10px) scale(.97)}to{opacity:1;transform:none}}

/* Người Việt nói → bên PHẢI */
.msg-group.vi { align-self:flex-end; align-items:flex-end; }
/* Người Trung nói → bên TRÁI */
.msg-group.zh { align-self:flex-start; align-items:flex-start; }

/* ── Avatar + tên ── */
.msg-meta {
  display:flex; align-items:center; gap:5px;
  font-size:10px; font-weight:600; letter-spacing:.6px;
  text-transform:uppercase;
  margin-bottom:1px;
}
.msg-group.vi .msg-meta { color:var(--vi); flex-direction:row-reverse; }
.msg-group.zh .msg-meta { color:var(--zh); }

.msg-flag { font-size:14px; }

/* ── Bubble gốc (VĂN BẢN THU ÂM – nhỏ, mờ) ── */
.bubble-original {
  padding:5px 11px;
  border-radius:12px;
  font-size:12px; font-weight:400; line-height:1.45;
  word-break:break-word;
  color:var(--t1); /* Làm sáng màu chữ nguyên bản (trước là --t3) */
  background:rgba(255,255,255,.08); /* Sáng nền một chút để nổi hơn */
  border:1px solid var(--border);
}

/* Không cần phân biệt màu riêng VI / ZH cho bubble gốc */
.msg-group.vi .bubble-original {
  border-bottom-right-radius:4px;
}
.msg-group.zh .bubble-original {
  border-bottom-left-radius:4px;
}

/* ── Bubble dịch (BẢN DỊCH – to, nổi bật) ── */
.bubble-translation {
  padding:10px 14px;
  border-radius:18px;
  font-size:var(--fs-bubble); font-weight:600;
  line-height:1.55; word-break:break-word;
  color:var(--t1);
}

.msg-group.vi .bubble-translation {
  background:var(--vi-light);
  border:1px solid rgba(245,158,11,.25);
  border-bottom-right-radius:5px;
}
/* Font chữ Kai cho toàn bộ nội dung Tiếng Trung
   Ma Shan Zheng – Google Fonts, đồng nhất iOS / Android / Windows / macOS */
.msg-group.zh .bubble-translation {
  background:var(--zh-light);
  border:1px solid rgba(239,68,68,.25);
  border-bottom-left-radius:5px;
  font-size:var(--fs-zh);
  font-family: 'Ma Shan Zheng', 'KaiTi', 'STKaiti', 'KaiTi_GB2312', 'FangSong', serif;
  letter-spacing: 0.05em;
}

/* Câu gốc TQ (bubble nhỏ bên dưới) cũng dùng Kai */
.msg-group.zh .bubble-original {
  font-family: 'Ma Shan Zheng', 'KaiTi', 'STKaiti', 'KaiTi_GB2312', 'FangSong', serif;
  letter-spacing: 0.04em;
}

/* Khi dịch VI→ZH, bản dịch tiếng Trung nằm trong msg-group.vi */
.msg-group.vi .bubble-translation {
  font-family: 'Ma Shan Zheng', 'KaiTi', 'STKaiti', 'KaiTi_GB2312', 'FangSong', serif;
  letter-spacing: 0.05em;
}

/* Bubble dịch tiếng Việt (khi người Trung nói) – rõ ràng dùng Be Vietnam Pro */
.msg-group.zh .bubble-translation {
  font-family: 'Be Vietnam Pro', system-ui, sans-serif;
  font-size: var(--fs-bubble);
  letter-spacing: 0;
}

.tr-flag { font-size:15px; opacity:.8; flex-shrink:0; margin-top:2px; }

/* Loading skeleton dịch */
.bubble-translation.loading {
  color:transparent;
  background:linear-gradient(90deg,
    rgba(255,255,255,.06) 25%,
    rgba(255,255,255,.12) 50%,
    rgba(255,255,255,.06) 75%);
  background-size:200% 100%;
  animation:shimmer 1.2s infinite;
  min-width:80px; min-height:30px;
  border:none;
}
@keyframes shimmer{0%{background-position:200% 0}100%{background-position:-200% 0}}

/* ── Interim bubble (đang gõ / nhận dạng dở) ── */
.interim-bubble {
  align-self:flex-start;
  display:flex; align-items:center; gap:8px;
  padding:8px 14px;
  background:rgba(255,255,255,.05);
  border:1px dashed rgba(255,255,255,.15);
  border-radius:14px;
  font-size:13px; font-style:italic; color:var(--t2);
  max-width:80%;
  animation:msgIn .2s var(--ease) both;
}
.interim-flag { font-size:14px; animation:blink 1s infinite; }
.interim-translate-btn {
  background: var(--purple);
  border: none;
  border-radius: 6px;
  color: white;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform .1s, opacity .1s;
}
.interim-translate-btn:active { opacity: .8; transform: scale(0.95); }

/* ================================================================
   BOTTOM BAR
================================================================ */
.bottom-bar {
  position:relative; z-index:20;
  height:var(--bottom-h);
  display:flex; align-items:center; justify-content:space-between;
  padding:0 24px;
  padding-bottom:env(safe-area-inset-bottom,0px);
  background:var(--bg-bottom);
  border-top:1px solid var(--border);
  backdrop-filter:blur(24px); -webkit-backdrop-filter:blur(24px);
  flex-shrink:0;
}

.mic-col { display:flex; flex-direction:column; align-items:center; gap:4px; }
.mic-lbl { font-size:10px; font-weight:600; color:var(--t3); letter-spacing:.4px; }

/* Mic button */
.mic-btn {
  position:relative;
  width:54px; height:54px;
  border:none; border-radius:50%;
  cursor:pointer; outline:none;
  display:flex; align-items:center; justify-content:center;
  transition:transform .3s var(--spring);
  -webkit-tap-highlight-color:transparent;
  overflow:hidden;
}
.mic-btn svg { width:22px; height:22px; color:#fff; position:relative; z-index:1; }

.vi-btn {
  background:radial-gradient(circle at 38% 32%, #fcd34d, #d97706, #92400e);
  box-shadow:0 4px 16px var(--vi-ring);
}
.zh-btn {
  background:radial-gradient(circle at 38% 32%, #f87171, #dc2626, #7f1d1d);
  box-shadow:0 4px 16px var(--zh-ring);
}

.mic-btn:hover  { transform:scale(1.08); }
.mic-btn:active { transform:scale(.91); }

/* Đang nghe → pulse */
.mic-btn.active { animation:micPulse 1.8s ease-in-out infinite; }
.vi-btn.active  { box-shadow:0 0 0 5px rgba(245,158,11,.2), 0 6px 22px var(--vi-ring); }
.zh-btn.active  { box-shadow:0 0 0 5px rgba(239,68,68,.2),  0 6px 22px var(--zh-ring); }
@keyframes micPulse{0%,100%{transform:scale(1)}50%{transform:scale(1.1)}}

/* Ripple ring khi active */
.ripple {
  position:absolute; inset:0; border-radius:50%;
  border:2px solid rgba(255,255,255,.35);
  opacity:0;
  transform:scale(.8);
  transition:none;
}
.mic-btn.active .ripple {
  animation:rippleOut 1.8s ease-out infinite;
}
@keyframes rippleOut{
  0%  {opacity:.7;transform:scale(.8)}
  100%{opacity:0; transform:scale(1.6)}
}

/* Mid column */
.mid-col {
  display:flex; flex-direction:column; align-items:center; gap:6px;
}

/* Loading ring */
.loading-ring {
  width:28px; height:28px; color:var(--purple);
  display:none;
  animation:spin 1s linear infinite;
}
.loading-ring.visible{display:block}
@keyframes spin{to{transform:rotate(360deg)}}

/* Clear button */
.clear-btn {
  width:34px; height:34px;
  background:rgba(255,255,255,.05);
  border:1px solid var(--border);
  border-radius:50%;
  color:var(--t3);
  display:flex; align-items:center; justify-content:center;
  cursor:pointer;
  transition:.25s var(--ease);
}
.clear-btn:hover{border-color:rgba(239,68,68,.4);color:#fca5a5;background:rgba(239,68,68,.08)}

/* Stop TTS button – chỉ hiện khi đang phát âm */
.stop-tts-btn {
  width:34px; height:34px;
  background:rgba(239,68,68,.15);
  border:1px solid rgba(239,68,68,.4);
  border-radius:50%;
  color:#fca5a5;
  display:none; align-items:center; justify-content:center;
  cursor:pointer;
  transition:.25s var(--ease);
  animation:ttspulse 1.4s ease-in-out infinite;
}
.stop-tts-btn.active { display:flex; }
.stop-tts-btn:hover { background:rgba(239,68,68,.3); transform:scale(1.1); }
@keyframes ttspulse {
  0%,100% { box-shadow:0 0 0 0 rgba(239,68,68,.4); }
  50%      { box-shadow:0 0 0 6px rgba(239,68,68,0); }
}

/* ================================================================
   TOAST
================================================================ */
.toast {
  position:fixed;
  bottom:calc(var(--bottom-h) + 10px);
  left:50%; transform:translateX(-50%) translateY(16px);
  background:rgba(15,15,40,.97);
  border:1px solid var(--border);
  border-radius:100px;
  padding:8px 18px;
  font-size:13px; font-weight:500; color:var(--t1);
  backdrop-filter:blur(16px);
  z-index:200;
  opacity:0; pointer-events:none;
  transition:all .3s var(--spring);
  white-space:nowrap;
  max-width:calc(100vw - 32px);
  overflow:hidden; text-overflow:ellipsis;
}
.toast.show{opacity:1;transform:translateX(-50%) translateY(0)}
.toast.success{border-color:rgba(16,185,129,.5);color:#6ee7b7}
.toast.error  {border-color:rgba(239,68,68,.5); color:#fca5a5}
.toast.info   {border-color:rgba(124,58,237,.5);color:#c4b5fd}

/* ================================================================
   ICON BUTTON (nút lịch sử trên header)
================================================================ */
.icon-btn {
  width:34px; height:34px;
  background:rgba(255,255,255,.05);
  border:1px solid var(--border);
  border-radius:10px;
  color:var(--t2);
  display:flex; align-items:center; justify-content:center;
  cursor:pointer;
  transition:.25s var(--ease);
  flex-shrink:0;
}
.icon-btn:hover { border-color:var(--purple); color:var(--purple); background:rgba(124,58,237,.1); }

/* ================================================================
   HISTORY PANEL – slide-in từ phải
================================================================ */
.history-overlay {
  position:fixed; inset:0; z-index:300;
  background:rgba(0,0,0,.5);
  backdrop-filter:blur(4px);
  opacity:0; pointer-events:none;
  transition:opacity .3s var(--ease);
}
.history-overlay.open { opacity:1; pointer-events:auto; }

.history-panel {
  position:fixed; top:0; right:0; bottom:0; z-index:301;
  width:min(360px, 96vw);
  background:#111128;
  border-left:1px solid var(--border);
  display:flex; flex-direction:column;
  transform:translateX(100%);
  transition:transform .35s var(--ease);
  box-shadow:-8px 0 40px rgba(0,0,0,.5);
}
.history-panel:not([hidden]) { transform:translateX(0); }
/* Khi panel mở overlay cũng mở */

/* Header panel */
.hp-header {
  display:flex; align-items:center; justify-content:space-between;
  padding:16px 16px 12px;
  border-bottom:1px solid var(--border);
  flex-shrink:0;
}
.hp-title { font-size:15px; font-weight:700; color:var(--t1); }
.hp-actions { display:flex; align-items:center; gap:8px; }

.hp-del-all {
  font-size:11px; font-weight:600;
  padding:4px 10px;
  background:transparent;
  border:1px solid rgba(239,68,68,.4);
  border-radius:100px;
  color:#fca5a5;
  cursor:pointer;
  transition:.2s var(--ease);
}
.hp-del-all:hover { background:rgba(239,68,68,.12); }

.hp-close {
  width:30px; height:30px;
  background:rgba(255,255,255,.05);
  border:1px solid var(--border);
  border-radius:8px;
  color:var(--t2);
  display:flex; align-items:center; justify-content:center;
  cursor:pointer;
  transition:.2s var(--ease);
}
.hp-close:hover { color:var(--t1); }

/* Scrollable list */
.hp-list {
  flex:1; overflow-y:auto; padding:12px;
  display:flex; flex-direction:column; gap:10px;
}
.hp-list::-webkit-scrollbar{width:3px}
.hp-list::-webkit-scrollbar-thumb{background:var(--border);border-radius:10px}

.hp-empty {
  text-align:center; color:var(--t3);
  font-size:13px; padding:40px 0;
}

/* Session card */
.hp-card {
  background:rgba(255,255,255,.04);
  border:1px solid var(--border);
  border-radius:14px;
  padding:12px 14px;
  cursor:pointer;
  transition:.2s var(--ease);
  animation:msgIn .3s var(--spring) both;
}
.hp-card:hover { border-color:rgba(124,58,237,.4); background:rgba(124,58,237,.06); }

.hp-card-top {
  display:flex; align-items:center; justify-content:space-between;
  margin-bottom:8px;
}
.hp-card-date { font-size:12px; font-weight:600; color:var(--t2); }
.hp-card-count {
  font-size:10px; font-weight:600;
  padding:2px 8px;
  background:rgba(124,58,237,.2);
  border-radius:100px;
  color:#c4b5fd;
}

/* Preview tin nhắn */
.hp-preview { display:flex; flex-direction:column; gap:4px; }
.hp-preview-msg {
  font-size:12px; color:var(--t3);
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
.hp-preview-msg span { font-weight:500; color:var(--t2); }

/* Nút xóa trong card */
.hp-card-footer {
  margin-top:10px; padding-top:8px;
  border-top:1px solid var(--border);
  display:flex; justify-content:flex-end;
}
.hp-del-one {
  font-size:11px; color:var(--t3);
  background:transparent; border:none;
  cursor:pointer; padding:2px 6px;
  border-radius:6px;
  transition:.2s var(--ease);
  display:flex; align-items:center; gap:4px;
}
.hp-del-one:hover { color:#fca5a5; background:rgba(239,68,68,.08); }

/* ================================================================
   PINYIN – nhỏ, mờ, nghiêng, hiện dưới chữ Trung
================================================================ */
.pinyin {
  display: block;
  font-family: 'Be Vietnam Pro', sans-serif; /* Đổi sang font Việt Nam */
  font-size: 11px;
  font-weight: 400;
  font-style: italic;
  color: var(--t2); /* Đổi từ t3 sang t2 để sáng hơn chút */
  margin-top: 4px;
  line-height: 1.4;
  letter-spacing: 0.3px;
  word-break: break-word;
}
/* Pinyin trong bubble-translation (nền màu) thì sáng hơn chút */
.bubble-translation .pinyin {
  color: rgba(255,255,255,.38);
}

/* ================================================================
   NÚT SỬA trên bubble-original
================================================================ */
.bubble-original {
  position: relative;
}
.edit-orig-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px; height: 18px;
  margin-left: 5px;
  vertical-align: middle;
  background: rgba(255,255,255,.07);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--t3);
  cursor: pointer;
  opacity: 0;
  transition: opacity .2s, color .2s;
  flex-shrink: 0;
}
.bubble-original:hover .edit-orig-btn { opacity: 1; }
.edit-orig-btn:hover { color: var(--t1); background: rgba(255,255,255,.12); }

/* Edit mode – textarea + actions */
.edit-wrapper {
  display: flex; flex-direction: column; gap: 6px;
  width: 100%;
}
.edit-textarea {
  width: 100%;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(124,58,237,.5);
  border-radius: 8px;
  color: var(--t1);
  font-family: inherit;
  font-size: 12px;
  line-height: 1.5;
  padding: 6px 8px;
  resize: none;
  outline: none;
}
.edit-textarea:focus { border-color: var(--purple); box-shadow: 0 0 0 2px rgba(124,58,237,.2); }

.edit-actions {
  display: flex; gap: 6px; justify-content: flex-end;
}
.edit-cancel, .edit-save {
  font-family: inherit;
  font-size: 11px; font-weight: 600;
  padding: 4px 10px;
  border-radius: 100px;
  cursor: pointer;
  transition: .2s var(--ease);
}
.edit-cancel {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--t3);
}
.edit-cancel:hover { color: var(--t1); }
.edit-save {
  background: linear-gradient(135deg, var(--purple), #8b5cf6);
  border: none;
  color: #fff;
  box-shadow: 0 2px 8px rgba(124,58,237,.4);
}
.edit-save:hover { opacity: .9; transform: translateY(-1px); }

/* ================================================================
   HISTORY – nút Xem và panel đầy đủ
================================================================ */
.hp-view-btn {
  font-size: 11px; color: #c4b5fd;
  background: rgba(124,58,237,.15);
  border: 1px solid rgba(124,58,237,.3);
  border-radius: 100px;
  cursor: pointer; padding: 3px 8px;
  display: flex; align-items: center; gap: 4px;
  transition: .2s var(--ease);
}
.hp-view-btn:hover { background: rgba(124,58,237,.28); }

/* Full-view inline */
.hp-full-view {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 6px;
  max-height: 280px;
  overflow-y: auto;
}
.hp-full-view::-webkit-scrollbar { width: 2px; }
.hp-full-view::-webkit-scrollbar-thumb { background: var(--border); }

.hp-msg-row {
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(255,255,255,.03);
  border: 1px solid var(--border);
}
.hp-msg-row.vi { border-left: 3px solid var(--vi); }
.hp-msg-row.zh { border-left: 3px solid var(--zh); }

.hp-msg-time { font-size: 9px; color: var(--t3); margin-bottom: 2px; }
.hp-msg-orig { font-size: 11px; color: var(--t2); }
.hp-msg-tr   { font-size: 12px; font-weight: 600; color: var(--t1); margin-top: 2px; }

/* ================================================================
   SETTINGS PANEL
================================================================ */
.sp-overlay {
  position:fixed; inset:0; z-index:300;
  background:rgba(0,0,0,.5); backdrop-filter:blur(4px);
  opacity:0; pointer-events:none; transition:opacity .3s var(--ease);
}
.sp-overlay.open { opacity:1; pointer-events:auto; }
.settings-panel {
  position:fixed; top:0; right:0; bottom:0; z-index:301;
  width:min(320px, 96vw); background:#111128;
  border-left:1px solid var(--border);
  display:flex; flex-direction:column;
  transform:translateX(100%); transition:transform .35s var(--ease);
  box-shadow:-8px 0 40px rgba(0,0,0,.5);
}
.settings-panel:not([hidden]) { transform:translateX(0); }
.sp-header {
  display:flex; align-items:center; justify-content:space-between;
  padding:16px 16px 12px; border-bottom:1px solid var(--border); flex-shrink:0;
}
.sp-title { font-size:15px; font-weight:700; color:var(--t1); }
.sp-close {
  width:30px; height:30px; background:rgba(255,255,255,.05);
  border:1px solid var(--border); border-radius:8px; color:var(--t2);
  display:flex; align-items:center; justify-content:center; cursor:pointer;
}
.sp-close:hover { color:var(--t1); }
.sp-body { flex:1; overflow-y:auto; padding:12px 16px; display:flex; flex-direction:column; gap:4px; }
.sp-section { padding:12px 0; border-bottom:1px solid var(--border); }
.sp-section:last-child { border-bottom:none; }
.sp-row { display:flex; align-items:center; justify-content:space-between; gap:12px; }
.sp-label { font-size:13px; font-weight:600; color:var(--t1); margin-bottom:8px; }
.sp-row .sp-label { margin-bottom:2px; }
.sp-sublabel { font-size:11px; color:var(--t3); }

/* Toggle switch iOS-style */
.sp-toggle { position:relative; display:inline-block; width:44px; height:26px; flex-shrink:0; }
.sp-toggle input { opacity:0; width:0; height:0; }
.sp-knob {
  position:absolute; inset:0; background:rgba(255,255,255,.12);
  border-radius:26px; cursor:pointer; transition:.3s var(--ease);
}
.sp-knob::before {
  content:''; position:absolute; width:20px; height:20px;
  left:3px; top:3px; background:#fff; border-radius:50%;
  transition:.3s var(--ease); box-shadow:0 1px 4px rgba(0,0,0,.4);
}
.sp-toggle input:checked + .sp-knob { background:var(--purple); }
.sp-toggle input:checked + .sp-knob::before { transform:translateX(18px); }

.sp-info {
  font-size:11px; color:var(--t3); background:rgba(124,58,237,.08);
  border:1px solid rgba(124,58,237,.2) !important; border-radius:10px;
  padding:10px 12px; display:flex; gap:7px; line-height:1.5;
}
.sp-info svg { flex-shrink:0; color:#c4b5fd; }
#speed-picker { width:100%; }
#speed-picker .fp-btn { flex:1; }

/* ── MSG META: nhỏ + song ngữ ── */
.msg-meta {
  display:flex; align-items:center; gap:4px;
  font-size:9px; font-weight:700; letter-spacing:.5px;
  text-transform:uppercase; margin-bottom:3px; opacity:.65;
}
.msg-group.vi .msg-meta { color:var(--vi); flex-direction:row-reverse; }
.msg-group.zh .msg-meta { color:var(--zh); }
.msg-arr { opacity:.4; font-size:8px; }

/* ── Hàng bao bọc bubble + nút loa ── */
.bubble-row {
  display:flex;
  align-items:center;
  gap:6px;
}
/* Nút loa nằm ngoài bubble, luôn hiện */
.bubble-speak-btn {
  flex-shrink:0;
  display:flex; align-items:center; justify-content:center;
  width:28px; height:28px;
  background:rgba(255,255,255,.07);
  border:1px solid rgba(255,255,255,.12);
  border-radius:50%;
  color:var(--t3);
  cursor:pointer;
  transition:color .2s var(--ease), background .2s var(--ease),
             transform .15s var(--ease), box-shadow .2s var(--ease);
}
.bubble-speak-btn:hover {
  color:#10b981;
  background:rgba(16,185,129,.15);
  border-color:rgba(16,185,129,.4);
  box-shadow:0 0 10px rgba(16,185,129,.3);
  transform:scale(1.1);
}
.bubble-speak-btn:active { transform:scale(.9); }
/* Căn chỉnh theo đường hướng */
.msg-group.vi .bubble-row { flex-direction:row-reverse; } /* Loa bên trái */
.msg-group.zh .bubble-row { flex-direction:row; }         /* Loa bên phải */
