:root {
  --bg: #e5ddd5;
  --frame: #efeae2;
  --ink: #111b21;
  --muted: #667781;
  --brand: #00a884;
  --navy: #075e54;
  --yellow: #fff3cd;
  --yellow-ink: #664d03;
  --mine-bg: #d9fdd3;
  --theirs-bg: #fff;
}
:root[data-theme="dark"] {
  --bg: #0b141a;
  --frame: #0b141a;
  --ink: #e9edef;
  --muted: #8696a0;
  --navy: #1f2c33;
  --mine-bg: #005c4b;
  --theirs-bg: #202c33;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  overflow: hidden;
  font-family: system-ui, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #d1d7db;
  color: var(--ink);
}
#app {
  max-width: 430px; margin: 0 auto;
  height: 100dvh;
  max-height: 100dvh;
  background: var(--frame);
  display: flex; flex-direction: column;
  box-shadow: 0 0 24px rgba(0,0,0,.18);
  overflow: hidden;
}
header.app {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px;
  background: var(--navy); color: #fff;
}
header.app h1 { font-size: 16px; margin: 0; flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
header.app button {
  background: transparent; color: #fff; border: 0; border-radius: 8px;
  padding: 6px 8px; font-size: 13px;
}
#msgs {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 8px 16px;
  display: flex; flex-direction: column; gap: 2px;
  background-color: var(--bg);
  background-image: radial-gradient(rgba(0,0,0,.04) 1px, transparent 1px);
  background-size: 18px 18px;
}
header.app, #banner, #replyBar, #composer, footer.legal { flex-shrink: 0; }
.bubble {
  position: relative;
  max-width: 78%;
  padding: 6px 8px 4px 9px;
  font-size: 14.5px;
  line-height: 1.35;
  box-shadow: 0 1px 0.5px rgba(11,20,26,.13);
}
.bubble.mine {
  align-self: flex-end;
  background: var(--mine-bg);
  border-radius: 8px 8px 0 8px;
  margin: 1px 8px 1px 40px;
}
.bubble.theirs {
  align-self: flex-start;
  background: var(--theirs-bg);
  border-radius: 0 8px 8px 8px;
  margin: 1px 40px 1px 8px;
}
.bubble.mine::after {
  content: "";
  position: absolute; right: -7px; bottom: 0;
  border: 6px solid transparent;
  border-left-color: var(--mine-bg);
  border-bottom-color: var(--mine-bg);
}
.bubble.theirs::after {
  content: "";
  position: absolute; left: -7px; bottom: 0;
  border: 6px solid transparent;
  border-right-color: var(--theirs-bg);
  border-bottom-color: var(--theirs-bg);
}
.bubble .sender-name {
  font-size: 12.5px;
  font-weight: 700;
  margin: 0 0 3px;
  line-height: 1.2;
}
.bubble .body { white-space: pre-wrap; word-break: break-word; }
.meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  text-align: right;
  float: right;
  padding-left: 10px;
}
#banner { background: var(--yellow); color: var(--yellow-ink); padding: 8px 10px; font-size: 13px; }
#composer {
  display: flex; gap: 8px; align-items: center;
  padding: 8px;
  background: #f0f2f5;
}
:root[data-theme="dark"] #composer { background: #1f2c33; }
#composer input, #composer textarea {
  flex: 1; border: 0; border-radius: 21px;
  padding: 10px 14px; font-size: 15px;
  background: #fff; color: var(--ink);
  font-family: inherit;
}
#composer textarea {
  resize: none; max-height: 120px; min-height: 42px;
  line-height: 1.35; overflow-y: auto;
}
:root[data-theme="dark"] #composer input,
:root[data-theme="dark"] #composer textarea { background: #2a3942; }
#composer button {
  background: #00a884; color: #fff; border: 0;
  width: 42px; height: 42px; border-radius: 50%;
  font-size: 13px;
}
footer.legal { font-size: 11px; color: var(--muted); text-align: center; padding: 6px 8px 10px; background: #f0f2f5; }
.modal { position: fixed; inset: 0; background: #0006; display: flex; align-items: center; justify-content: center; z-index: 20; }
.modal .box { width: 90%; max-width: 360px; background: var(--theirs-bg); padding: 16px; border-radius: 12px; color: var(--ink); }
.hidden { display: none !important; }
.list button {
  display: block; width: 100%; text-align: left; padding: 10px; margin: 6px 0;
  border: 0; border-radius: 10px; background: #f0f2f5; color: var(--ink);
}

#replyBar {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border-left: 4px solid #00a884;
  margin: 0 8px; padding: 6px 8px; border-radius: 8px;
}
#replyBar.hidden { display: none !important; }
#replyBarText { flex: 1; font-size: 13px; color: #667781; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#replyBarClose { border: 0; background: transparent; font-size: 20px; color: #667; }
.quote {
  background: rgba(0,0,0,.06);
  border-left: 3px solid #00a884;
  padding: 4px 6px; margin-bottom: 4px;
  border-radius: 4px; font-size: 12px; color: #667781;
}
.quote b { display: block; color: #075e54; font-size: 12px; }
.sheet-btn {
  display: block; width: 100%; margin: 6px 0; padding: 12px;
  border: 0; border-radius: 10px; background: #f0f2f5; font-size: 15px;
}
.sheet-btn.danger { color: #b42318; }
.sheet-btn.primary { background: #00a884; color: #fff; }

.box input, .box select {
  width: 100%; margin: 6px 0; padding: 10px; border-radius: 8px; border: 1px solid #ddd; font-size: 15px;
}
.tabs { display: flex; gap: 8px; }

#settingsModal .box label, #settingsModal .box input, #settingsModal .box select { display: block; width: 100%; margin: 6px 0; }
#settingsModal .box input, #settingsModal .box select { padding: 10px; border-radius: 8px; border: 1px solid #0002; }
#settingsModal .muted { color: #667781; font-size: 13px; }

.otp-digits { display: flex; gap: 6px; justify-content: space-between; margin: 10px 0; }
.otp-d {
  width: 42px; height: 48px; text-align: center; font-size: 22px; font-weight: 700;
  border: 1px solid #ccc; border-radius: 8px; padding: 0;
}

.bubble.sys {
  align-self: center;
  background: transparent;
  box-shadow: none;
  max-width: 90%;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  margin: 8px 16px;
}
.bubble.sys::after { display: none; }
.bubble.sys .body { text-align: center; }
.bubble.sys .meta { display: none; }

.origToggle {
  display: block; margin-top: 4px; padding: 0;
  border: 0; background: none; color: var(--muted);
  font-size: 11px; cursor: pointer;
}
.orig { font-size: 12px; color: var(--muted); margin-top: 4px; white-space: pre-wrap; }

.sheet-btn.loading { opacity: 0.85; pointer-events: none; }
.spin {
  display: inline-block; width: 14px; height: 14px; margin-right: 6px;
  border: 2px solid rgba(255,255,255,.35); border-top-color: #fff;
  border-radius: 50%; vertical-align: -2px;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#banner{background:#fff3cd;color:#7a5b00;padding:8px 12px;font-size:13px;text-align:center;}
#banner.hidden,#banner:empty{display:none;}
.plan-box{margin:12px 0;}

#attachBtn{
  flex:0 0 42px;width:42px;height:42px;min-width:42px;padding:0;
  background:#00a884;color:#fff;border:0;border-radius:50%;
  display:flex;align-items:center;justify-content:center;
}
#attachBtn svg{display:block;}
.bubble img.chatimg{max-width:220px;max-height:220px;border-radius:8px;display:block;margin-top:4px;}

.attach-sheet{position:fixed;inset:0;z-index:30;display:flex;flex-direction:column;justify-content:flex-end;}
.attach-sheet.hidden{display:none !important;}
.attach-sheet-bg{position:absolute;inset:0;background:#0006;}
.attach-sheet-panel{
  position:relative;z-index:1;
  background:#e9edef;color:#111b21;
  border-radius:16px 16px 0 0;
  padding:16px 12px 20px;
  max-width:430px;width:100%;margin:0 auto;
  transform:translateY(110%);
  animation:sheetUp .22s ease forwards;
}
@keyframes sheetUp{to{transform:translateY(0);}}
.attach-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:10px;}
.attach-item{background:transparent;border:0;color:#111b21;display:flex;flex-direction:column;align-items:center;gap:6px;padding:6px 0;}
.attach-ico{width:52px;height:52px;border-radius:50%;display:flex;align-items:center;justify-content:center;}
.attach-lab{font-size:11px;color:#111b21;}

.bubble img.chatimg,.bubble video.chatvid{max-width:220px;max-height:220px;border-radius:8px;display:block;margin-top:4px;}
.bubble audio.chataud{width:200px;margin-top:4px;}
.bubble a.chatfile{display:block;margin-top:4px;color:#00a884;}

.chatfile-row{display:flex;align-items:center;gap:8px;margin-top:4px;text-decoration:none;color:inherit;}
.chatfile-ico{width:36px;height:36px;border-radius:8px;background:#0ea5e9;display:flex;align-items:center;justify-content:center;flex-shrink:0;}
.chatfile-name{font-size:11px;line-height:1.25;word-break:break-all;font-size:13px;word-break:break-all;}

.bubble{padding-right:22px;}
.bubble-more{
  position:absolute;top:2px;right:2px;
  width:22px;height:22px;padding:0;border:0;border-radius:11px;
  background:transparent;color:#667781;opacity:.75;
  display:flex;align-items:center;justify-content:center;
}
.bubble.mine .bubble-more{color:#54656f;}
.bubble-more:hover{opacity:1;background:rgba(0,0,0,.06);}

#msgModal .box{
  padding:8px 8px 12px;border-radius:16px;
  background:#fff;
}
:root[data-theme="dark"] #msgModal .box{background:#202c33;}
#msgModalTitle{
  margin:4px 8px 10px;font-size:13px;font-weight:700;color:#667781;text-transform:uppercase;letter-spacing:.04em;
}
#msgModalBody .sheet-btn{
  background:#f6f6f6;margin:4px 0;border-radius:12px;font-size:16px;padding:14px;
}
:root[data-theme="dark"] #msgModalBody .sheet-btn{background:#2a3942;color:#e9edef;}
#msgModalBody .sheet-btn.danger{background:#fde8e8;color:#b42318;}
#msgModalBody .sheet-btn.primary{background:#e7f8f2;color:#075e54;}

.media-viewer{
  position:fixed;inset:0;z-index:40;background:#000e;
  display:flex;align-items:center;justify-content:center;
}
.media-viewer img,.media-viewer video{
  max-width:100%;max-height:100%;object-fit:contain;
}
.media-viewer-close{
  position:absolute;top:10px;right:12px;z-index:1;
  width:40px;height:40px;border:0;border-radius:20px;
  background:#0008;color:#fff;font-size:28px;line-height:1;
}
.bubble img.chatimg,.bubble video.chatvid{cursor:pointer;}

header.app button{display:flex;align-items:center;justify-content:center;min-width:36px;}
header.app button svg{display:block;}
#themeBtn{font-size:11px;white-space:nowrap;}

.room-title-bar{
  flex-shrink:0;background:#f0f2f5;color:#111b21;
  padding:6px 8px 6px 12px;font-size:13px;font-weight:600;
  display:flex;align-items:center;gap:8px;
}
#roomTitleText{flex:1;min-width:0;text-align:left;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
#menuToggle,#helpBtn{flex-shrink:0;}
header.app{
  max-height:140px;opacity:1;
  transition:max-height .45s ease, opacity .45s ease, padding .45s ease;
  overflow:hidden;
  flex-wrap:wrap;
}
header.app button{flex-shrink:0;}
header.app.collapsed{
  max-height:0;opacity:0;padding-top:0;padding-bottom:0;pointer-events:none;
}
.menu-switch{position:relative;display:inline-flex;align-items:center;flex-shrink:0;}
.menu-switch input{position:absolute;opacity:0;width:0;height:0;}
.menu-switch-ui{
  width:40px;height:22px;border-radius:11px;background:#c5c9ce;
  display:block;position:relative;transition:background .25s;
}
.menu-switch-ui::after{
  content:"";position:absolute;top:2px;left:2px;
  width:18px;height:18px;border-radius:50%;background:#fff;
  transition:transform .25s;
}
.menu-switch input:checked + .menu-switch-ui{background:#00a884;}
.menu-switch input:checked + .menu-switch-ui::after{transform:translateX(18px);}

header.app #homeBtn img{display:block;width:18px;height:18px;object-fit:contain;}

:root[data-theme="dark"] .room-title-bar{background:#1f2c33;color:#e9edef;}
.room-title-bar.hidden{display:none !important;}
header.app h1{display:none;}

header.app{gap:4px;}
header.app button{
  flex-direction:column;gap:2px;min-width:44px;padding:4px 4px 6px;
  font-size:10px;line-height:1;
}
header.app button span{color:#fff;font-size:10px;}

header.app{
  justify-content:center;
}
header.app h1{display:none;}

.day-sep{
  align-self:center;
  margin:10px 0 8px;
  padding:4px 10px;
  border-radius:8px;
  background:rgba(225,245,254,.92);
  color:#54656f;
  font-size:12px;
  font-weight:600;
  box-shadow:0 1px 0.5px rgba(11,20,26,.08);
}
:root[data-theme="dark"] .day-sep{background:#182229;color:#8696a0;}

.bubble .body a{color:#027eb5;text-decoration:underline;word-break:break-all;}
.link-preview{display:block;margin-top:6px;max-width:220px;text-decoration:none;}
.link-preview img{width:100%;border-radius:8px;display:block;}
.link-preview span{display:block;font-size:11px;color:#027eb5;margin-top:3px;}

#langModal .box{max-height:80vh;display:flex;flex-direction:column;}
#langList{overflow-y:auto;max-height:60vh;-webkit-overflow-scrolling:touch;}

.ai-debug{
  flex-shrink:0;max-height:88px;overflow:auto;
  margin:0;padding:6px 8px;font-size:10px;line-height:1.35;
  background:#111;color:#9f9;white-space:pre-wrap;word-break:break-word;
}

#aiDebug.hidden{display:none !important;}

.quota-warn{color:#dc2626;font-size:11px;font-weight:600;margin-top:4px;}

#roomsModal .box{max-height:80vh;display:flex;flex-direction:column;overflow:hidden;}
#roomList{flex:1 1 auto;min-height:0;overflow-y:auto;max-height:55vh;-webkit-overflow-scrolling:touch;}

html, body, #app{
  height: 100svh;
  height: 100dvh;
  max-height: 100svh;
  max-height: 100dvh;
}
#app{
  padding-bottom: env(safe-area-inset-bottom);
}
#composer{
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}

#voiceModal .box{max-height:80vh;display:flex;flex-direction:column;}
#voiceList{overflow-y:auto;max-height:50vh;}

body.cn{
  --bg:#f2f2f2; --frame:#fff; --mine-bg:#d9fdd3; --theirs-bg:#fff;
}
body.cn #msgs{background-image:none;}
body.cn .bubble{box-shadow:none;}
body.cn .bubble.mine::after, body.cn .bubble.theirs::after{display:none;}
body.cn .attach-sheet-panel{animation:none;}
body.cn #paypal-button-container{display:none !important;}
body.cn header.app button span{letter-spacing:0;}

/* Default grey */
#voiceBtn {
  color: red;               /* text colour */
}
#voiceBtn svg {
  stroke: red;              /* icon colour */
}

/* Active state (when Auto Voice is ON) */
#voiceBtn.active {
  color: white;            /* choose your colour – e.g. blue */
}
#voiceBtn.active svg {
  stroke: white;
}

.presence-row{display:flex;align-items:center;gap:10px;padding:8px 4px;}
.presence-dot{width:10px;height:10px;border-radius:50%;flex-shrink:0;}
.presence-dot.on{background:#22c55e;}
.presence-dot.off{background:#ef4444;}
#presenceList{max-height:50vh;overflow:auto;}

#recordBtn{
  flex:0 0 42px;width:42px;height:42px;min-width:42px;padding:0;
  background:#e11d48;color:#fff;border:0;border-radius:50%;
  display:flex;align-items:center;justify-content:center;
}
#recordBtn.rec{background:#be123c;animation:recpulse 1s ease infinite;}
@keyframes recpulse{50%{transform:scale(1.06);}}

.auth-brand{text-align:center;margin:0 0 12px;}
.auth-logo{width:88px;height:88px;object-fit:contain;display:block;margin:0 auto 10px;}
.auth-slogan{margin:0 0 8px;font-size:14px;font-weight:700;line-height:1.35;color:var(--ink);}
.auth-blurb{margin:0 0 8px;font-size:12px;line-height:1.45;color:var(--muted);}

.title-favicon{width:18px;height:18px;object-fit:contain;flex-shrink:0;}
#settingsModal .auth-logo{width:48px;height:48px;margin-bottom:6px;}

#inviteLangModal .box{max-height:80vh;display:flex;flex-direction:column;}
#inviteLangList{overflow-y:auto;max-height:55vh;-webkit-overflow-scrolling:touch;}

.settings-head{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:8px;}
.settings-head h3{margin:0;}
.dash-btn{flex:0 0 auto;width:auto;padding:6px 10px;border:0;border-radius:8px;background:#075e54;color:#fff;font-size:12px;font-weight:700;}
.name-row{display:flex;align-items:center;gap:8px;margin:8px 0;}
.name-row input{flex:1;min-width:0;margin:0;}
.name-save{flex:0 0 40px;width:40px;height:40px;border:0;border-radius:10px;background:#00a884;display:flex;align-items:center;justify-content:center;}

.pref-row{display:flex;align-items:center;gap:8px;margin:8px 0;}
.pref-row select{flex:1;min-width:0;margin:0;}
.pref-row #settingsTheme{flex:0 0 auto;width:auto;white-space:nowrap;}

.field-lab{display:block;font-size:13px;font-weight:600;margin:10px 0 4px;color:var(--ink);}

.theme-ico{
  flex:0 0 auto;display:flex;flex-direction:column;align-items:center;justify-content:center;
  gap:2px;min-width:44px;padding:4px 6px;border:0;border-radius:8px;
  background:#075e54;color:#fff;font-size:10px;line-height:1;
}
.theme-ico svg{display:block;}
.theme-ico span{color:#fff;font-size:10px;}

footer.legal a{color:inherit;text-decoration:underline;}

#send{display:flex;align-items:center;justify-content:center;padding:0;}
#send svg{display:block;}

.load-more{
  align-self:center;margin:6px auto;padding:2px 8px;border:0;background:transparent;
  color:#8aa0a8;font-size:11px;font-weight:500;
}

#roomsBtn{position:relative;}
.rooms-badge{
  position:absolute;top:0;right:2px;min-width:16px;height:16px;padding:0 4px;
  border-radius:8px;background:#ef4444;color:#fff;font-size:10px;font-weight:700;
  line-height:16px;text-align:center;
}
#roomsBtn.rooms-blink{animation:roomsBlink 1.1s ease-in-out infinite;}
@keyframes roomsBlink{50%{filter:brightness(1.8);transform:scale(1.06);}}
.room-unread{float:right;background:#ef4444;color:#fff;border-radius:10px;padding:1px 6px;font-size:11px;margin-left:8px;}

#msgModal .box{max-width:340px;width:86%;}
.ico-btn{display:flex;align-items:center;gap:10px;text-align:left;}
.act-ico{width:20px;text-align:center;flex-shrink:0;}
.whisper-fab{
  position:absolute;right:14px;bottom:92px;z-index:15;
  width:52px;height:52px;border:0;border-radius:26px;
  background:#ccff00;color:#075e54;box-shadow:0 4px 14px #0003;
}
.whisper-fab .wf-ico{font-size:22px;}
.whisper-fab .wf-n{
  position:absolute;top:-4px;right:-4px;min-width:18px;height:18px;padding:0 5px;
  border-radius:9px;background:#ef4444;color:#fff;font-size:11px;line-height:18px;
}
.whisper-fab.pop{animation:wfPop .45s ease;}
@keyframes wfPop{0%{transform:scale(.4);opacity:0}60%{transform:scale(1.12)}100%{transform:scale(1);opacity:1}}
#app{position:relative;}

.presence-row{display:flex;align-items:center;gap:8px;flex-wrap:nowrap;}
.presence-row .pname{flex:1;min-width:0;}
.presence-acts{display:flex;align-items:center;gap:10px;margin-left:auto;flex-shrink:0;}
.presence-act{
  display:inline-flex;align-items:center;justify-content:center;
  width:22px;height:22px;line-height:1;font-size:18px;
  background:none;border:0;padding:0;margin:0;color:#075e54;
  -webkit-appearance:none;appearance:none;cursor:pointer;
}

html.dark .presence-act{color:#d9fdd3;}

.presence-mail{font-size:22px;width:26px;height:26px;}

.menu-eye{border:0;background:transparent;color:#fff;padding:4px;margin-left:auto;display:inline-flex;align-items:center;justify-content:center;}
.menu-eye .eye-shut{display:none;}
.menu-eye:not(.is-open) .eye-open{display:none;}
.menu-eye:not(.is-open) .eye-shut{display:block;}
.room-title-bar .menu-eye{color:#111b21;}
:root[data-theme="dark"] .room-title-bar .menu-eye{color:#e9edef;}
#helpBtn{font-weight:800;font-size:13px;border:0;border-radius:50%;width:18px;height:18px;background:#0078D4;color:#fff !important;line-height:18px;padding:0;}

.help-list{max-height:55vh;overflow:auto;text-align:left;margin:8px 0 12px;}
.help-row{display:flex;gap:10px;padding:6px 0;border-bottom:1px solid #eee;font-size:13px;}
.help-row b{min-width:92px;flex-shrink:0;color:#075e54;}
html.dark .help-row{border-color:#333;}

.help-ico{width:28px;height:28px;flex-shrink:0;display:inline-flex;align-items:center;justify-content:center;color:#075e54;}
.help-ico svg{width:20px;height:20px;}
.help-ico img{width:18px;height:18px;}
.help-ico svg path,.help-ico svg circle,.help-ico svg rect{stroke:#075e54;}
.help-ico svg [fill="#fff"]{fill:#075e54;}
.help-txt{display:flex;flex-direction:column;gap:2px;min-width:0;}
.help-txt b{min-width:0;}
.help-q{display:inline-flex;width:20px;height:20px;border-radius:50%;background:#0078D4;color:#fff;font-weight:800;font-size:14px;align-items:center;justify-content:center;}

.help-brand{text-align:center;padding:4px 0 12px;border-bottom:1px solid #eee;margin-bottom:8px;}
.help-logo{width:64px;height:64px;object-fit:contain;display:block;margin:0 auto 8px;}
.help-slogan{font-size:13px;font-weight:600;color:#075e54;margin:0 0 6px;line-height:1.35;}
.help-blurb{font-size:12px;color:#54656f;margin:0;line-height:1.35;}
.help-homechip{display:inline-flex;width:22px;height:22px;background:#075e54;border-radius:4px;align-items:center;justify-content:center;}
.help-homechip img{width:16px;height:16px;}

.help-sub{margin:12px 0 8px;font-size:20px;font-weight:700;color:#075e54;text-align:left;}
#helpTitle:empty{display:none;}

#helpClose{display:block;width:100%;}

.lobby-tips{padding:16px 18px 8px;max-width:92%;}
.lobby-tip{background:#fff;border-radius:10px 10px 10px 2px;padding:8px 12px;margin:8px 0;box-shadow:0 1px 0.5px rgba(0,0,0,.13);color:#111b21;font-size:15px;line-height:1.4;white-space:pre-wrap;min-height:1.2em;}
html.dark .lobby-tip{background:#202c33;color:#e9edef;}

.room-row{display:flex;align-items:center;gap:6px;margin:4px 0;width:100%;}
.room-row .room-open{flex:1;width:auto !important;min-width:0;text-align:left;margin:0 !important;}
.room-leave{flex-shrink:0;background:none;border:0;color:#b42318;padding:0 4px;height:auto;display:inline-flex;align-items:center;gap:4px;font-size:12px;cursor:pointer;white-space:nowrap;}
html.dark .room-leave{background:#2a3942;color:#f85149;}

.typing-line{flex-shrink:0;padding:2px 16px 4px;font-size:12px;color:#667781;font-style:italic;min-height:18px;}
html.dark .typing-line{color:#8696a0;}

.auth-home-wrap{margin:12px 0 0;text-align:center;}
.auth-home{font-size:14px;font-weight:700;color:var(--green,#075E54);text-decoration:none;}

.room-qr{flex-shrink:0;width:36px;height:36px;display:inline-flex;align-items:center;justify-content:center;cursor:pointer;background:#fff;border:0;border-radius:8px;color:#111;padding:4px;}
html.dark .room-qr{background:#fff;color:#111;border:0;}
#qrImg{image-rendering:pixelated;}

.room-leave svg{width:20px;height:20px;}
.room-leave{min-height:36px;font-size:13px;}

footer.legal{position:relative;}
.footer-qr{display:inline-flex;align-items:center;justify-content:center;vertical-align:middle;margin-left:6px;width:22px;height:22px;background:transparent;border:0;padding:0;cursor:pointer;}
.footer-qr.hidden{display:none !important;}

.bubble.pending{opacity:.65;}
.bubble.pending .meta::after{content:" ⏳";}

#footerSummary{
  flex:0 0 42px;width:42px;height:42px;min-width:42px;padding:0;
  background:#00a884;color:#fff;border:0;border-radius:50%;
  display:flex;align-items:center;justify-content:center;
  font-size:18px;line-height:1;
}
#footerSummary.used{background:#8aa9a0;opacity:.7;}
#footerSummary.hidden{display:none !important;}

.summary-body{width:100%;box-sizing:border-box;min-height:180px;max-height:50vh;text-align:left;font-size:14px;line-height:1.45;margin:8px 0;padding:8px;border:1px solid #ccc;border-radius:8px;resize:vertical;}

.summary-wait{display:flex;align-items:center;gap:10px;margin:8px 0;color:#555;font-size:14px;}
.summary-wait.hidden{display:none;}
.summary-spin{width:18px;height:18px;border:2px solid #ddd;border-top-color:#1d4ed8;border-radius:50%;animation:summarySpin .8s linear infinite;flex:0 0 18px;}
@keyframes summarySpin{to{transform:rotate(360deg);}}
#summaryModal .box button:disabled,#summaryBody:disabled{opacity:.55;pointer-events:none;}

#attachBtn,#footerSummary,#recordBtn{
  transition:width .22s ease,height .22s ease,min-width .22s ease,flex-basis .22s ease,font-size .22s ease,opacity .22s ease;
}
#composer.typing-mini #attachBtn,
#composer.typing-mini #footerSummary,
#composer.typing-mini #recordBtn{
  width:22px;height:22px;min-width:22px;flex-basis:22px;font-size:11px;
}
#composer.typing-mini #attachBtn svg,
#composer.typing-mini #footerSummary svg,
#composer.typing-mini #recordBtn svg{
  width:12px;height:12px;
}

.voice-row{display:flex;align-items:center;gap:8px;max-width:230px;padding:4px 6px;background:rgba(0,0,0,.06);border-radius:18px;margin:4px 0;}
.voice-ico{font-size:16px;line-height:1;}
.chataud{width:160px;height:32px;max-width:100%;}
.bubble.deleted .voice-row,.bubble.deleted .chataud{display:none;}

.footer-poll{display:inline-flex;align-items:center;justify-content:center;vertical-align:middle;margin-left:6px;width:22px;height:22px;}
.footer-poll.hidden{display:none !important;}
.footer-poll.is-poll circle{stroke:#22c55e;fill:#22c55e;}
.footer-poll.is-off circle{stroke:#ef4444;fill:#ef4444;}
.footer-poll.is-poll circle:first-child{fill:none;}
.footer-poll.is-off circle:first-child{fill:none;}


#menuSlider{overflow:hidden;flex-shrink:0;background:var(--navy);}
#menuTrack{display:flex;width:200%;transition:transform .28s ease;}
#menuTrack > header.app{flex:0 0 50%;width:50%;min-width:50%;}
#menuSlider.tools #menuTrack{transform:translateX(-50%);}










.menu-handle{
  width:16px;min-width:16px;align-self:stretch;
  margin:0;padding:0;border:0;border-radius:0;
}
#moreMenuBtn{margin-left:auto;margin-right:-10px;background:transparent;}
#backMenuBtn{margin-left:-10px;margin-right:4px;background:transparent;}
#toolsMenu{background:#1e3a8a;justify-content:flex-start;padding-left:0;}
#toolsMenu button{color:#fff;}
#menuSlider.tools{background:#1e3a8a;}

#moreMenuBtn{position:relative;}
#moreMenuBtn::after{
  content:'>';
  position:absolute;left:50%;top:50%;
  transform:translate(-50%,-50%);
  color:#fff;font-size:13px;font-weight:700;line-height:1;
  animation:menu-nudge 1.1s ease-in-out infinite;
}
@keyframes menu-nudge{
  0%,100%{transform:translate(-70%,-50%);}
  50%{transform:translate(-20%,-50%);}
}
#menuSlider.tools #moreMenuBtn::after{animation:none;}

#backMenuBtn{position:relative;}
#backMenuBtn::after{
  content:'<';
  position:absolute;left:50%;top:50%;
  transform:translate(-50%,-50%);
  color:#fff;font-size:13px;font-weight:700;
  animation:menu-nudge-back 1.1s ease-in-out infinite;
}
@keyframes menu-nudge-back{
  0%,100%{transform:translate(-20%,-50%);}
  50%{transform:translate(-70%,-50%);}
}

#mainMenu{padding-right:0;}
#toolsMenu{padding-left:0;}
#moreMenuBtn{margin-right:0;}
#backMenuBtn{margin-left:0;}

#menuSlider.collapsed{max-height:0;opacity:0;pointer-events:none;overflow:hidden;}

/* ============================================================
   SEARCH (in-thread find) — Tools bar
   ============================================================ */

/* Tools bar: same blue as the ? help icon */
#toolsMenu {
  background: #0078D4;
  flex-wrap: nowrap !important;   /* don't wrap to another row */
  overflow: hidden;               /* clip anything pushed past the edge */
  justify-content: flex-start;    /* keep back button on the left */
}
#menuSlider.tools { background: #0078D4; }

/* Search box: slide-in / slide-out animation */
.search-box {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 250px;  /* pushes Ask AI + Currency past the right edge */
  margin-left: 4px;
  max-width: 400px;
  opacity: 1;
  overflow: hidden;
  transition:
    max-width   0.30s cubic-bezier(0.4, 0, 0.2, 1),
    opacity     0.22s ease,
    margin-left 0.30s cubic-bezier(0.4, 0, 0.2, 1);
}
/* Collapsed state — override global .hidden (which uses display:none) so we can animate */
.search-box.hidden {
  display: flex !important;
  max-width: 0;
  min-width: 0 !important;   /* ← new: cancel the min-width above */
  opacity: 0;
  margin-left: 0;
  pointer-events: none;
}

/* Short text field */
.search-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 30px;
  padding: 4px 10px;
  border: 0;
  border-radius: 15px;
  background: #fff;
  color: #111b21;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.search-input::placeholder { color: #6b7280; }
.search-input::-webkit-search-cancel-button { display: none; }

/* Match counter, e.g. 3/17 */
.search-count {
  flex: 0 0 auto;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  min-width: 30px;
  text-align: center;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

/* ▲ ▼ ✕ round buttons on the tools bar */
#toolsMenu .search-nav,
#toolsMenu .search-close {
  flex: 0 0 26px;
  width: 26px;
  height: 26px;
  min-width: 26px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-direction: row;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
#toolsMenu .search-nav:active,
#toolsMenu .search-close:active {
  background: rgba(255, 255, 255, 0.35);
}
#toolsMenu .search-close {
  font-size: 14px;
  font-weight: 500;
}

/* Highlighted bubble — thinner, brighter yellow */
.bubble.search-hit {
  outline: 2px solid #ffe600;
  outline-offset: 1px;
  box-shadow: 0 0 6px 1px rgba(255, 230, 0, 0.85),
              0 0 0 1px rgba(255, 230, 0, 0.35) inset;
  background-color: rgba(255, 230, 0, 0.18);
  animation: searchHitPulse 2.5s ease;
  transition: outline-color 0.3s ease, box-shadow 0.3s ease, background-color 0.3s ease;
}
@keyframes searchHitPulse {
  0%   { outline-color: #ffff66; box-shadow: 0 0 0 0 rgba(255, 230, 0, 0.95), 0 0 0 1px rgba(255, 230, 0, 0.45) inset; background-color: rgba(255, 230, 0, 0.30); }
  30%  { outline-color: #ffe600; box-shadow: 0 0 8px 1.5px rgba(255, 230, 0, 0.95), 0 0 0 1px rgba(255, 230, 0, 0.45) inset; background-color: rgba(255, 230, 0, 0.24); }
  100% { outline-color: #ffe600; box-shadow: 0 0 6px 1px rgba(255, 230, 0, 0.85), 0 0 0 1px rgba(255, 230, 0, 0.35) inset; background-color: rgba(255, 230, 0, 0.18); }
}

/* Dark theme — same tools bar blue */
:root[data-theme="dark"] #toolsMenu { background: #0078D4; }
:root[data-theme="dark"] .search-input { background: #fff; color: #111b21; }

/* ============================================================
   AI error replies (quota exhausted, AI failed)
   ============================================================ */
.bubble.bubble-error {
  background: #fee2e2 !important;
  outline: 1px solid #fecaca;
}
.bubble.bubble-error .body {
  color: #b91c1c;
  font-weight: 600;
}
/* Match the little tail triangles */
.bubble.bubble-error.mine::after {
  border-left-color: #fee2e2;
  border-bottom-color: #fee2e2;
}
.bubble.bubble-error.theirs::after {
  border-right-color: #fee2e2;
  border-bottom-color: #fee2e2;
}

/* Dark theme */
:root[data-theme="dark"] .bubble.bubble-error {
  background: #3b0a0a !important;
  outline-color: #7f1d1d;
}
:root[data-theme="dark"] .bubble.bubble-error .body {
  color: #fca5a5;
}
:root[data-theme="dark"] .bubble.bubble-error.mine::after {
  border-left-color: #3b0a0a;
  border-bottom-color: #3b0a0a;
}
:root[data-theme="dark"] .bubble.bubble-error.theirs::after {
  border-right-color: #3b0a0a;
  border-bottom-color: #3b0a0a;
}

/* ============================================================
   ASK AI — Tools bar
   ============================================================ */

/* The box mirrors the search box: same slide-in/out animation */
.ask-ai-box {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 180px;
  margin-left: 4px;
  max-width: 400px;
  opacity: 1;
  overflow: hidden;
  transition:
    max-width   0.30s cubic-bezier(0.4, 0, 0.2, 1),
    opacity     0.22s ease,
    margin-left 0.30s cubic-bezier(0.4, 0, 0.2, 1);
}
.ask-ai-box.hidden {
  display: flex !important;
  max-width: 0;
  min-width: 0 !important;   /* ← new */
  opacity: 0;
  margin-left: 0;
  pointer-events: none;
}

/* Text input — same shape as search input */
.ask-ai-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 30px;
  padding: 4px 10px;
  border: 0;
  border-radius: 15px;
  background: #fff;
  color: #111b21;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.ask-ai-input::placeholder { color: #6b7280; }

/* ➤ send button — same round style as ▲/▼/✕ */
#toolsMenu .ask-ai-send,
#toolsMenu .ask-ai-close {
  flex: 0 0 26px;
  width: 26px;
  height: 26px;
  min-width: 26px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-direction: row;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
#toolsMenu .ask-ai-send:active,
#toolsMenu .ask-ai-close:active {
  background: rgba(255, 255, 255, 0.35);
}
#toolsMenu .ask-ai-send {
  font-size: 14px;
  padding-left: 2px; /* nudge ➤ visually centered */
}
#toolsMenu .ask-ai-close {
  font-size: 14px;
  font-weight: 500;
}

/* Dark theme — keeps the tools bar blue */
:root[data-theme="dark"] .ask-ai-input { background: #fff; color: #111b21; }

/* ------------------------------------------------------------
   Generic X close button for modals
   ------------------------------------------------------------ */
.modal-x {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(0,0,0,0.06);
  color: #667781;
  font-size: 16px;
  font-weight: 500;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  z-index: 2;
}
.modal-x:active {
  background: rgba(0,0,0,0.14);
}
:root[data-theme="dark"] .modal-x {
  background: rgba(255,255,255,0.08);
  color: #e9edef;
}
:root[data-theme="dark"] .modal-x:active {
  background: rgba(255,255,255,0.18);
}

/* Make room for the X in the settings header */
#settingsModal .settings-head {
  padding-right: 38px;
}

/* ============================================================
   CURRENCY CONVERTER — modal
   ============================================================ */

#currencyModal .box {
  max-width: 380px;
}

#currencyTitle {
  margin: 0 0 14px;
  font-size: 17px;
  font-weight: 700;
}

/* Row: label above, inputs below */
.currency-row {
  margin: 12px 0;
}
.currency-row.currency-to-row {
  margin-bottom: 6px;
}

.currency-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 6px 2px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

/* Side-by-side select + amount input */
.currency-inputs {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

/* Dropdown */
.currency-select {
  flex: 0 0 58%;           /* wider — was 42% */
  min-width: 0;
  height: 44px;
  padding: 0 10px;
  border: 1px solid #ddd;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;         /* smaller — was 15px */
  font-family: inherit;
  font-weight: 600;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4l4 4 4-4' fill='none' stroke='%23667781' stroke-width='2' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

/* Amount input */
.currency-amount {
  flex: 1 1 auto;
  min-width: 0;
  height: 44px;
  padding: 0 12px;
  border: 1px solid #ddd;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-size: 16px;
  font-family: inherit;
  font-weight: 600;
  text-align: right;
  -webkit-appearance: none;
  appearance: none;
}
.currency-amount:focus,
.currency-select:focus {
  outline: none;
  border-color: #00a884;
  box-shadow: 0 0 0 2px rgba(0, 168, 132, 0.15);
}

/* Swap button (To row) */
.currency-swap {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid #ddd;
  border-radius: 10px;
  background: #f0f2f5;
  color: #075e54;
  font-size: 18px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.currency-swap:active {
  background: #e5e7eb;
}

/* Result card */
.currency-result {
  margin: 14px 0 8px;
  padding: 14px 16px;
  border-radius: 12px;
  background: linear-gradient(135deg, #e7f8f2 0%, #d9fdd3 100%);
  border: 1px solid #b7e3d0;
  text-align: center;
}
.currency-result.hidden { display: none !important; }

.currency-result-main {
  font-size: 20px;
  font-weight: 700;
  color: #075e54;
  line-height: 1.3;
  word-break: break-word;
}

.currency-result-sub {
  margin-top: 6px;
  font-size: 12px;
  color: #4b6660;
  line-height: 1.4;
  word-break: break-word;
}

/* Dark theme */
:root[data-theme="dark"] .currency-select,
:root[data-theme="dark"] .currency-amount {
  background: #2a3942;
  border-color: #3b4a52;
  color: #e9edef;
}
:root[data-theme="dark"] .currency-select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4l4 4 4-4' fill='none' stroke='%238696a0' stroke-width='2' stroke-linecap='round'/></svg>");
}
:root[data-theme="dark"] .currency-swap {
  background: #2a3942;
  border-color: #3b4a52;
  color: #ccff00;
}
:root[data-theme="dark"] .currency-swap:active {
  background: #1f2c33;
}
:root[data-theme="dark"] .currency-result {
  background: linear-gradient(135deg, #0d3d34 0%, #075e54 100%);
  border-color: #1a6d5c;
}
:root[data-theme="dark"] .currency-result-main {
  color: #b8f5e0;
}
:root[data-theme="dark"] .currency-result-sub {
  color: #9dd4c2;
}
#currencySendWrap { margin-top: -2px; }

/* ============================================================
   CURRENCY MODAL — blue theme (matches tools bar #0078D4)
   ============================================================ */

/* Primary button (Convert) */
#currencyModal .sheet-btn.primary {
  background: #0078D4;
  color: #fff;
}
#currencyModal .sheet-btn.primary:active {
  background: #0066b5;
}

/* Secondary button (Send to group) */
#currencyModal .sheet-btn {
  background: #e6f2fb;
  color: #0056a3;
  font-weight: 600;
}
#currencyModal .sheet-btn:active {
  background: #cfe6f7;
}

/* Close X (reuses .modal-x from Settings) */
#currencyModal .modal-x {
  background: #e6f2fb;
  color: #0056a3;
}
#currencyModal .modal-x:active {
  background: #cfe6f7;
}

/* Input focus ring */
#currencyModal .currency-select:focus,
#currencyModal .currency-amount:focus {
  border-color: #0078D4;
  box-shadow: 0 0 0 2px rgba(0, 120, 212, 0.2);
}

/* Swap button */
#currencyModal .currency-swap {
  border-color: #9cc7e8;
  background: #e6f2fb;
  color: #0056a3;
}
#currencyModal .currency-swap:active {
  background: #cfe6f7;
}

/* Modal title */
#currencyModal h3 {
  color: #0056a3;
}

/* Labels (FROM / TO) */
#currencyModal .currency-label {
  color: #35648c;
}

/* Result card — already blue, kept here for completeness */
#currencyModal .currency-result {
  background: linear-gradient(135deg, #e6f2fb 0%, #cfe6f7 100%);
  border: 1px solid #9cc7e8;
}
#currencyModal .currency-result-main {
  color: #0056a3;
}
#currencyModal .currency-result-sub {
  color: #35648c;
}

/* Dark theme overrides */
:root[data-theme="dark"] #currencyModal .sheet-btn {
  background: #0a2e4d;
  color: #b8dcf5;
}
:root[data-theme="dark"] #currencyModal .sheet-btn:active {
  background: #0d4a7a;
}
:root[data-theme="dark"] #currencyModal .sheet-btn.primary {
  background: #0078D4;
  color: #fff;
}
:root[data-theme="dark"] #currencyModal .sheet-btn.primary:active {
  background: #0066b5;
}
:root[data-theme="dark"] #currencyModal .modal-x {
  background: #0a2e4d;
  color: #b8dcf5;
}
:root[data-theme="dark"] #currencyModal .modal-x:active {
  background: #0d4a7a;
}
:root[data-theme="dark"] #currencyModal .currency-swap {
  background: #0a2e4d;
  border-color: #1a6d9e;
  color: #b8dcf5;
}
:root[data-theme="dark"] #currencyModal .currency-swap:active {
  background: #0d4a7a;
}
:root[data-theme="dark"] #currencyModal h3 {
  color: #b8dcf5;
}
:root[data-theme="dark"] #currencyModal .currency-label {
  color: #9dc6e0;
}
.room-search-box{display:flex;align-items:center;gap:4px;margin:0 0 8px;}
.room-search-input{flex:1;min-width:0;height:32px;padding:4px 10px;border:1px solid #ddd;border-radius:16px;font-size:13px;font-family:inherit;}
.room-search-box .search-nav{flex:0 0 28px;width:28px;height:28px;border:0;border-radius:50%;background:#e6f2fb;color:#0056a3;font-size:11px;font-weight:700;}
.room-row.room-hit{outline:2px solid #ffe600;border-radius:10px;background:rgba(255,230,0,.18);}
.presence-kick{color:#b42318;font-size:16px;cursor:pointer;margin-left:4px;}
#roomsModal .box{max-height:80vh;overflow:hidden;display:flex;flex-direction:column;}
#roomList{flex:1;min-height:0;overflow-y:auto;max-height:55vh;-webkit-overflow-scrolling:touch;}


/* Agent typing indicator */
.agent-typing .agent-dots {
  display: inline-block;
  letter-spacing: 2px;
  animation: agentPulse 1.2s ease-in-out infinite;
  opacity: 0.7;
}
@keyframes agentPulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}


/* Agent room — conversational bubbles (not system notices) */
.bubble.theirs.agent-bubble {
  max-width: 85%;
}
.bubble.theirs.agent-bubble .sender-name {
  font-weight: 600;
  font-size: 12px;
  margin-bottom: 2px;
}


/* ===== Personal sticky note ===== */
#noteModal.modal {
  z-index: 80;
  align-items: flex-start;
  padding-top: 6vh;
  overflow-y: auto;
}

#noteBtn { position: relative; }
#noteBtn.has-note::after {
  content: '';
  position: absolute; top: 6px; right: 8px;
  width: 8px; height: 8px; border-radius: 50%;
  background: #facc15; box-shadow: 0 0 0 2px rgba(0,0,0,.25);
}
.note-paper {
  position: relative;
  width: min(420px, 92vw);
  margin: 8vh auto 0;
  padding: 28px 22px 18px;
  background:
    linear-gradient(180deg, #fff9c4 0%, #fef08a 40%, #fde047 100%);
  color: #422006;
  border-radius: 4px 4px 6px 6px;
  box-shadow:
    0 1px 0 rgba(255,255,255,.6) inset,
    0 12px 28px rgba(0,0,0,.28),
    0 2px 6px rgba(0,0,0,.12);
  transform: rotate(-1.2deg);
  font-family: initial;
}
.note-paper::before {
  content: '';
  position: absolute; inset: 0;
  background-image: repeating-linear-gradient(
    transparent, transparent 27px,
    rgba(180, 140, 40, .18) 27px, rgba(180, 140, 40, .18) 28px
  );
  background-position: 0 52px;
  pointer-events: none;
  border-radius: inherit;
  opacity: .85;
}
.note-tape {
  position: absolute;
  top: -10px; left: 50%;
  width: 88px; height: 22px;
  margin-left: -44px;
  background: linear-gradient(180deg, rgba(255,255,255,.55), rgba(255,255,255,.2));
  border: 1px solid rgba(255,255,255,.35);
  box-shadow: 0 2px 4px rgba(0,0,0,.12);
  transform: rotate(-2deg);
}
.note-x {
  position: absolute; top: 10px; right: 10px;
  border: 0; background: transparent; color: #78350f;
  font-size: 16px; cursor: pointer; opacity: .7;
}
.note-x:hover { opacity: 1; }
.note-title {
  margin: 4px 0 6px; font-size: 1.15rem; font-weight: 700;
  position: relative; z-index: 1;
  font-family: initial;
}
.note-hint {
  margin: 0 0 10px; font-size: .78rem; opacity: .75;
  font-family: initial; position: relative; z-index: 1;
  line-height: 1.35;
}
.note-textarea {
  position: relative; z-index: 1;
  width: 100%; min-height: 180px; resize: vertical;
  border: 0; background: transparent; color: #422006;
  font-size: 1.05rem; line-height: 28px;
  padding: 4px 2px; outline: none;
  font-family: initial;
}
.note-meta {
  position: relative; z-index: 1;
  text-align: right; font-size: .72rem; opacity: .6;
  font-family: initial; margin-top: 4px;
}
.note-actions {
  position: relative; z-index: 1;
  display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px;
}
.note-btn {
  border: 0; border-radius: 999px; padding: 9px 16px;
  font-weight: 600; cursor: pointer; font-family: initial; font-size: .9rem;
}
.note-btn-ghost {
  background: rgba(120, 53, 15, .12); color: #78350f;
}
.note-btn-solid {
  background: #78350f; color: #fef9c3;
  box-shadow: 0 4px 10px rgba(120, 53, 15, .25);
}
.note-btn-solid:hover { filter: brightness(1.08); }

/* Floating sticky — left bottom, above composer / green tools */
.note-fab {
  position: fixed;
  left: max(14px, env(safe-area-inset-left));
  bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  z-index: 40;
  width: 54px; height: 54px;
  border: 0; padding: 0; cursor: pointer;
  background: linear-gradient(160deg, #fef08a, #facc15 55%, #eab308);
  border-radius: 6px 6px 8px 4px;
  box-shadow:
    0 8px 20px rgba(0,0,0,.28),
    0 2px 4px rgba(0,0,0,.12);
  transform: rotate(-6deg);
  animation: noteFloat 3.2s ease-in-out infinite;
  display: flex; align-items: center; justify-content: center;
}
.note-fab:hover {
  transform: rotate(-2deg) scale(1.06);
  animation: none;
}
.note-fab-pin {
  position: absolute; top: -6px; left: 50%; margin-left: -5px;
  width: 10px; height: 10px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fecaca, #ef4444 70%);
  box-shadow: 0 2px 3px rgba(0,0,0,.25);
}
.note-fab-body { font-size: 22px; line-height: 1; filter: drop-shadow(0 1px 0 rgba(255,255,255,.4)); }
@keyframes noteFloat {
  0%, 100% { transform: rotate(-6deg) translateY(0); }
  50% { transform: rotate(-4deg) translateY(-5px); }
}
@media (max-width: 480px) {
  .note-fab { bottom: calc(96px + env(safe-area-inset-bottom, 0px)); width: 48px; height: 48px; }
}
:root[data-theme="dark"] .note-paper {
  box-shadow: 0 12px 32px rgba(0,0,0,.55);
}


/* =========================================================
   Motion system — iOS / macOS style (respects reduced-motion)
   ========================================================= */
:root {
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.3, 0.64, 1);
  --ease-soft: cubic-bezier(0.4, 0, 0.2, 1);
  --dur-fast: .18s;
  --dur: .32s;
  --dur-slow: .48s;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---- Message bubbles: rise + fade (live & history) ---- */
#msgs .bubble {
  animation: bubbleIn var(--dur) var(--ease-out) both;
  will-change: transform, opacity;
}
#msgs .bubble.mine {
  animation-name: bubbleInMine;
}
#msgs .bubble.theirs,
#msgs .bubble.agent-bubble {
  animation-name: bubbleInTheirs;
}
#msgs .bubble.sys {
  animation-name: bubbleInSys;
}
#msgs .bubble._prepend {
  animation-duration: .2s;
}
@keyframes bubbleInMine {
  from { opacity: 0; transform: translate3d(18px, 12px, 0) scale(.96); }
  to   { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}
@keyframes bubbleInTheirs {
  from { opacity: 0; transform: translate3d(-18px, 12px, 0) scale(.96); }
  to   { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}
@keyframes bubbleInSys {
  from { opacity: 0; transform: translate3d(0, 8px, 0); }
  to   { opacity: 1; transform: translate3d(0, 0, 0); }
}

/* Soft glass / depth on bubbles (skip heavy CN mode) */
body:not(.cn) #msgs .bubble.mine,
body:not(.cn) #msgs .bubble.theirs {
  box-shadow:
    0 1px 2px rgba(0,0,0,.06),
    0 6px 16px rgba(0,0,0,.06);
  transition: box-shadow var(--dur-fast) var(--ease-soft), transform var(--dur-fast) var(--ease-soft);
}
body:not(.cn) #msgs .bubble.mine:active,
body:not(.cn) #msgs .bubble.theirs:active {
  transform: scale(.985);
}

/* ---- Modals: dim + scale like iOS sheet ---- */
.modal {
  background: rgba(0,0,0,.0);
  backdrop-filter: blur(0);
  -webkit-backdrop-filter: blur(0);
  transition:
    background var(--dur) var(--ease-soft),
    backdrop-filter var(--dur) var(--ease-soft),
    -webkit-backdrop-filter var(--dur) var(--ease-soft);
  align-items: flex-end;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.modal:not(.hidden) {
  background: rgba(15, 23, 42, .42);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
/* sheetIn for modals removed — use macWindowOpen */
  transform-origin: center center;
}
@keyframes sheetIn {
  from { opacity: 0; transform: translate3d(0, 28px, 0) scale(.94); }
  to   { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}
/* Centered dialogs still use same motion but origin center */
.modal {
  justify-content: center;
  align-items: center;
  padding-bottom: 0;
}

/* ---- Room list rows ---- */
.room-row {
  animation: rowIn .36s var(--ease-out) both;
  transition: transform var(--dur-fast) var(--ease-soft), background var(--dur-fast);
}
.room-row:nth-child(1) { animation-delay: .02s; }
.room-row:nth-child(2) { animation-delay: .05s; }
.room-row:nth-child(3) { animation-delay: .08s; }
.room-row:nth-child(4) { animation-delay: .11s; }
.room-row:nth-child(5) { animation-delay: .14s; }
.room-row:nth-child(6) { animation-delay: .17s; }
.room-row:nth-child(7) { animation-delay: .2s; }
.room-row:nth-child(8) { animation-delay: .23s; }
@keyframes rowIn {
  from { opacity: 0; transform: translate3d(-12px, 0, 0); }
  to   { opacity: 1; transform: translate3d(0, 0, 0); }
}
.room-row:active {
  transform: scale(.98);
}

/* ---- Header / menu tools ---- */
#menuSlider button,
header.app button,
#composer button,
.sheet-btn,
.ico-btn {
  transition:
    transform var(--dur-fast) var(--ease-spring),
    opacity var(--dur-fast) var(--ease-soft),
    background var(--dur-fast) var(--ease-soft),
    box-shadow var(--dur-fast) var(--ease-soft);
}
#menuSlider button:active,
header.app button:active,
#composer button:active,
.sheet-btn:active,
.ico-btn:active {
  transform: scale(.92);
  opacity: .88;
}

/* Tools panel slide */
#menuSlider {
  transition: transform var(--dur) var(--ease-out), opacity var(--dur) var(--ease-soft);
}
#menuSlider.tools {
  /* if layout already handles tools class, soft fade of sections */
}

/* Composer bar */
#composer {
  transition: box-shadow var(--dur) var(--ease-soft), background var(--dur) var(--ease-soft);
}
#composer:focus-within {
  box-shadow: 0 -8px 24px rgba(0,0,0,.08);
}

/* Day separators */
.day-sep {
  animation: fadeUp .4s var(--ease-out) both;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Title bar */
.room-title-bar {
  transition: opacity var(--dur) var(--ease-soft), transform var(--dur) var(--ease-out);
}
.room-title-bar:not(.hidden) {
  animation: fadeUp .35s var(--ease-out) both;
}

/* Note fab already floats — add press */
.note-fab:active {
  transform: rotate(-2deg) scale(.92) !important;
  animation: none;
}

/* Send success micro bounce on last bubble */
@keyframes bubblePop {
  0% { transform: scale(.92); }
  60% { transform: scale(1.03); }
  100% { transform: scale(1); }
}
#msgs .bubble.mine.just-sent {
  animation: bubbleInMine var(--dur) var(--ease-out) both, bubblePop .45s var(--ease-spring) .05s both;
}

/* Smooth scroll feel */
#msgs {
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* Overlay sheets (attach etc.) */
.attach-sheet:not(.hidden) {
  animation: sheetIn var(--dur) var(--ease-spring) both;
}

/* Presence / list items */
#presenceList button,
#msgModalBody button {
  transition: transform var(--dur-fast) var(--ease-spring), background var(--dur-fast);
}
#presenceList button:active,
#msgModalBody button:active {
  transform: scale(.96);
}

/* Soft page wash when content area loads */
#msgs.msgs-enter {
  animation: msgsWash .5s var(--ease-out) both;
}
@keyframes msgsWash {
  from { opacity: .35; }
  to { opacity: 1; }
}


/* Global AI thinking overlay */
.ai-thinking {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  z-index: 60;
  display: flex;
  justify-content: center;
  pointer-events: none;
  animation: fadeUp .25s ease both;
}
.ai-thinking.hidden { display: none !important; }
.ai-thinking-card {
  display: flex; align-items: center; gap: 10px;
  background: rgba(15, 23, 42, .88);
  color: #f8fafc;
  padding: 10px 16px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  font-size: .9rem;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.ai-thinking-spin {
  width: 18px; height: 18px;
  border: 2.5px solid rgba(255,255,255,.25);
  border-top-color: #38bdf8;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
#noteBody[readonly] {
  opacity: .95;
  cursor: default;
  caret-color: transparent;
}
#noteEditBtn:not(.hidden) { display: inline-block; }


/* ===== App window shell (Mac / iPhone style) ===== */
html {
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(56,189,248,.12), transparent 55%),
    linear-gradient(165deg, #c5ccd3 0%, #d8dee4 40%, #b8c0c8 100%);
}
body {
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}
#app {
  max-width: 430px;
  width: 100%;
  margin: 0 auto;
  height: min(100dvh, 920px);
  max-height: 100dvh;
  border-radius: 18px;
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(255,255,255,.35) inset,
    0 1px 2px rgba(0,0,0,.06),
    0 12px 40px rgba(0,0,0,.18),
    0 40px 80px rgba(0,0,0,.12);
  background: var(--frame);
  display: flex;
  flex-direction: column;
  isolation: isolate;
}
/* Full-bleed on very small phones in standalone, keep soft corners */
@media (max-width: 480px) {
  body { padding: 0; align-items: stretch; }
  #app {
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    box-shadow: none;
  }
  /* Still round when not edge-to-edge PWA on slightly larger phones */
}
@media (min-width: 481px) and (max-width: 900px) {
  body { padding: 10px; }
  #app {
    border-radius: 16px;
    height: calc(100dvh - 20px);
    max-height: calc(100dvh - 20px);
  }
}
@media (min-width: 901px) {
  body { padding: 16px; }
  #app {
    border-radius: 20px;
    height: min(100dvh - 32px, 900px);
    max-height: calc(100dvh - 32px);
  }
}
/* Standalone PWA: full screen, no outer margin chrome */
@media (display-mode: standalone) {
  body { padding: 0; align-items: stretch; }
  #app {
    border-radius: 0;
    height: 100dvh;
    max-height: 100dvh;
    max-width: 100%;
    box-shadow: none;
  }
}

/* ===== Modal open: Mac-style stretch / scale window ===== */
.modal {
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0);
  backdrop-filter: blur(0px);
  -webkit-backdrop-filter: blur(0px);
  transition: background .28s cubic-bezier(0.22, 1, 0.36, 1),
              backdrop-filter .28s ease,
              -webkit-backdrop-filter .28s ease;
}
.modal:not(.hidden) {
  background: rgba(15, 23, 42, .45);
  backdrop-filter: blur(12px) saturate(1.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
}
.modal .box,
.modal .note-paper,
.modal .help-box {
  position: relative;
  border-radius: 16px;
  animation: macWindowOpen .42s cubic-bezier(0.16, 1, 0.3, 1) both;
  transform-origin: center center;
  box-shadow:
    0 0 0 1px rgba(255,255,255,.12) inset,
    0 20px 50px rgba(0,0,0,.28),
    0 8px 16px rgba(0,0,0,.12);
}
@keyframes macWindowOpen {
  0% {
    opacity: 0;
    transform: scale(0.86);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}
.modal.hidden .box,
.modal.hidden .note-paper {
  animation: none;
}
.help-box .modal-x,
.modal .box .modal-x {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: rgba(0,0,0,.06);
  color: inherit;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.help-box .modal-x:hover,
.modal .box .modal-x:hover {
  background: rgba(0,0,0,.12);
}
.help-box #helpTitle {
  padding-right: 36px;
}
@media (prefers-reduced-motion: reduce) {
  .modal .box,
  .modal .note-paper {
    animation: none !important;
  }
}


/* Scroll to bottom — floating glass control */
.scroll-bottom-btn {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  z-index: 35;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #0f172a;
  background: rgba(255,255,255,.55);
  backdrop-filter: blur(12px) saturate(1.3);
  -webkit-backdrop-filter: blur(12px) saturate(1.3);
  box-shadow:
    0 0 0 1px rgba(255,255,255,.5) inset,
    0 6px 20px rgba(0,0,0,.14);
  transition: opacity .2s ease, transform .2s cubic-bezier(0.34, 1.3, 0.64, 1);
  animation: fadeUp .25s ease both;
}
.scroll-bottom-btn.hidden { display: none !important; }
.scroll-bottom-btn:active { transform: scale(.9); }
:root[data-theme="dark"] .scroll-bottom-btn {
  color: #f1f5f9;
  background: rgba(30,41,59,.55);
  box-shadow:
    0 0 0 1px rgba(255,255,255,.08) inset,
    0 6px 20px rgba(0,0,0,.35);
}
/* Keep FAB above composer; on desktop #app is centered — pin relative to viewport is OK */
@media (min-width: 481px) {
  .scroll-bottom-btn {
    /* Align roughly with app column when centered */
    right: max(14px, calc(50% - 215px + 14px));
  }
}

/* Modal: only Mac center-scale open (override corner stretch) */
.modal .box,
.modal .note-paper,
.modal .help-box {
  transform-origin: center center !important;
  animation: macWindowOpen .45s cubic-bezier(0.16, 1, 0.3, 1) both !important;
}
@keyframes macWindowOpen {
  0% {
    opacity: 0;
    transform: scale(0.86);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}


/* ===== Agent notice meteor attract (流星) ===== */
.note-fab.note-meteor {
  animation:
    noteMeteorFly 1.45s cubic-bezier(0.16, 1, 0.3, 1) both,
    noteMeteorPulse 1.6s ease-in-out 1.45s infinite;
  z-index: 45;
}
.note-fab.note-meteor .note-fab-body {
  filter: drop-shadow(0 0 6px #fde047) drop-shadow(0 0 12px #fbbf24);
}
/* Sparkle trail stars */
.note-fab.note-meteor::before,
.note-fab.note-meteor::after {
  content: '✦';
  position: absolute;
  pointer-events: none;
  color: #fef08a;
  text-shadow: 0 0 8px #facc15, 0 0 14px #fff;
  animation: noteStarTwinkle 0.9s ease-in-out infinite;
}
.note-fab.note-meteor::before {
  font-size: 14px;
  top: -8px;
  right: -18px;
  animation-delay: 0s;
}
.note-fab.note-meteor::after {
  content: '✧';
  font-size: 11px;
  bottom: -6px;
  right: -12px;
  animation-delay: .25s;
}
.note-meteor-stars {
  position: absolute;
  inset: -20px -40px -20px -10px;
  pointer-events: none;
  overflow: visible;
}
.note-meteor-stars span {
  position: absolute;
  color: #fef9c3;
  text-shadow: 0 0 6px #fde047, 0 0 12px #f59e0b;
  animation: noteStarStreak 1.2s ease-out both;
  opacity: 0;
}
@keyframes noteMeteorFly {
  0% {
    opacity: 0;
    /* Start far off-screen (right + up) */
    transform: translate3d(min(70vw, 320px), -120px, 0) rotate(32deg) scale(0.25);
    filter: brightness(2.2) blur(1px);
  }
  15% {
    opacity: 1;
    filter: brightness(1.8) blur(0);
  }
  55% {
    /* Approach final seat */
    transform: translate3d(28px, -18px, 0) rotate(-2deg) scale(0.95);
    filter: brightness(1.25);
  }
  78% {
    /* Soft overshoot into place */
    transform: translate3d(-8px, 6px, 0) rotate(-9deg) scale(1.1);
  }
  100% {
    opacity: 1;
    /* Exact resting position of the FAB */
    transform: translate3d(0, 0, 0) rotate(-6deg) scale(1);
    filter: brightness(1);
  }
}
@keyframes noteMeteorPulse {
  0%, 100% {
    box-shadow:
      0 8px 20px rgba(0,0,0,.28),
      0 0 0 0 rgba(250, 204, 21, 0.5);
  }
  50% {
    box-shadow:
      0 8px 24px rgba(250, 204, 21, .35),
      0 0 0 10px rgba(250, 204, 21, 0);
    transform: rotate(-4deg) scale(1.06);
  }
}
@keyframes noteStarTwinkle {
  0%, 100% { opacity: .3; transform: scale(0.7) rotate(0deg); }
  50% { opacity: 1; transform: scale(1.3) rotate(20deg); }
}
@keyframes noteStarStreak {
  0% {
    opacity: 0;
    transform: translate3d(60px, -30px, 0) scale(0.3);
  }
  30% { opacity: 1; }
  100% {
    opacity: 0;
    transform: translate3d(-20px, 10px, 0) scale(1);
  }
}
/* Menu Note button soft glow when unread agent notice */
#noteBtn.has-note.note-meteor-btn {
  animation: noteBtnGlow 1.4s ease-in-out infinite;
}
#noteBtn.has-note.note-meteor-btn::after {
  animation: noteDotPulse 1s ease-in-out infinite;
  background: #facc15;
  box-shadow: 0 0 0 0 rgba(250, 204, 21, .7);
}
@keyframes noteBtnGlow {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.35) drop-shadow(0 0 6px #fde047); }
}
@keyframes noteDotPulse {
  0% { box-shadow: 0 0 0 0 rgba(250, 204, 21, .7); transform: scale(1); }
  70% { box-shadow: 0 0 0 8px rgba(250, 204, 21, 0); transform: scale(1.2); }
  100% { box-shadow: 0 0 0 0 rgba(250, 204, 21, 0); transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .note-fab.note-meteor,
  #noteBtn.has-note.note-meteor-btn,
  #noteBtn.has-note.note-meteor-btn::after {
    animation: none !important;
  }
}
