:root {
  color-scheme: light;
  --ink: #15253a;
  --muted: #596c80;
  --brand: #116b61;
  --brand-dark: #0c5149;
  --surface: #fff;
  --line: #dbe5ea;
  --page: #f0f5f6;
  font: 16px/1.5 system-ui, "Microsoft YaHei", sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--page); }
.topbar {
  min-height: 64px; display: flex; justify-content: space-between; align-items: center;
  gap: 12px; padding: 10px max(16px, calc((100vw - 760px) / 2));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 36px; height: 36px; }
h1 { font-size: 1.125rem; margin: 0; }
h2 { font-size: 1.35rem; margin: 0 0 8px; }
main { max-width: 792px; margin: auto; padding: 18px 16px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 20px; }
.login-panel { max-width: 420px; margin: clamp(16px, 7vh, 66px) auto 0; }
.login-panel button { width: 100%; margin-top: 6px; }
.muted { color: var(--muted); margin: 0 0 18px; }
label { display: block; margin: 0 0 12px; }
input:not([type=checkbox]):not([type=file]), select {
  display: block; width: 100%; min-width: 0; min-height: 44px; margin-top: 4px;
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: #f8fafb; color: var(--ink); font: inherit;
}
input:focus-visible, select:focus-visible, button:focus-visible, summary:focus-visible, .image:focus-within {
  outline: 2px solid var(--brand); outline-offset: 2px;
}
button {
  min-height: 42px; padding: 8px 15px; border: 1px solid transparent; border-radius: 10px;
  background: var(--brand); color: white; font: inherit; font-weight: 650;
  white-space: nowrap; cursor: pointer;
}
button:hover { background: var(--brand-dark); }
button.secondary { background: #eaf5f2; color: var(--brand-dark); }
button.secondary:hover { background: #dbeee9; }
button:disabled, .image:has(input:disabled) { opacity: .48; cursor: default; }
fieldset { margin: 8px 0 16px; border: 1px solid var(--line); border-radius: 10px; }
fieldset label { display: inline-flex; align-items: center; gap: 6px; margin: 4px 14px 4px 0; }
input[type=checkbox] { accent-color: var(--brand); }
#status { color: #9a3625; margin: 0 0 12px; padding: 9px 12px; background: #fff4ee; border-radius: 10px; }
#status:empty { display: none; }
.chat-panel { padding: 0; overflow: hidden; }
.conversation { display: flex; align-items: end; gap: 10px; padding: 12px; }
.conversation label { margin: 0; flex: 1; min-width: 0; color: var(--muted); font-size: .85rem; }
.conversation select { color: var(--ink); font-size: 1rem; }
.call-actions, .row { display: flex; gap: 8px; }
#messages { height: clamp(190px, 52vh, 580px); overflow: auto; padding: 12px; background: #edf3f5; }
.empty { text-align: center; color: var(--muted); font-size: .9rem; margin: 36px 0; }
.bubble {
  width: fit-content; max-width: min(86%, 34rem); margin: 0 0 9px; padding: 8px 11px;
  border: 1px solid #e1e9ec; border-radius: 4px 14px 14px 14px;
  background: white; white-space: pre-wrap; overflow-wrap: anywhere;
}
.mine { margin-left: auto; background: #dcf3eb; border-color: #cbe9e0; border-radius: 14px 4px 14px 14px; }
.bubble small { display: block; margin-bottom: 2px; color: var(--muted); font-size: .75rem; }
.bubble img { display: block; max-width: 100%; max-height: 31vh; border-radius: 8px; }
.message-actions { margin-top: 4px; color: var(--muted); font-size: .75rem; }
.message-actions summary { cursor: pointer; }
.message-actions button { min-height: 32px; margin: 4px 4px 0 0; padding: 3px 8px; font-size: .75rem; }
.composer { display: flex; align-items: center; gap: 8px; padding: 10px; }
.composer #message { margin: 0; flex: 1; }
.image {
  position: relative; display: grid; place-items: center; flex: 0 0 44px; height: 44px;
  margin: 0; border-radius: 10px; background: #eaf5f2; color: var(--brand-dark); font-size: 1.4rem;
}
.image input { position: absolute; inset: 0; width: 100%; opacity: 0; cursor: pointer; }
#call { margin: 0 12px 10px; padding: 10px; background: #edf5f4; border-radius: 12px; }
#callStatus { margin: 0 0 6px; }
video { max-width: 100%; max-height: 28vh; border-radius: 8px; }
#local { width: 24%; }
@media (max-width: 480px) {
  main { padding: 10px 8px; }
  .topbar { min-height: 56px; padding: 7px 12px; }
  .chat-panel { border-radius: 14px; }
  #messages { height: clamp(180px, 46vh, 440px); }
  .call-actions button { padding-inline: 11px; }
}

/* Conversation list and chat */
:root { --brand: #07a153; --brand-dark: #08733f; --page: #ededed; --ink: #181818; }
.topbar { background: #ededed; }
.chat-panel { border-color: #e0e0e0; }
.conversation-list h2 { padding: 13px 16px; margin: 0; border-bottom: 1px solid #efefef; font-size: 1.08rem; }
.conversation-item {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 16px;
  border: 0; border-radius: 0; background: white; color: var(--ink); text-align: left; font-weight: 400;
}
.conversation-item + .conversation-item { border-top: 1px solid #f1f1f1; }
.conversation-item:hover { background: #f5f5f5; }
.conversation-item > span:last-child { min-width: 0; }
.conversation-item strong, .conversation-item small { display: block; overflow: hidden; text-overflow: ellipsis; }
.conversation-item small { color: #737373; font-size: .85rem; }
.conversation-avatar { position: relative; display: flex; flex: 0 0 44px; }
.unread-badge {
  position: absolute; top: -5px; right: -6px;
  min-width: 18px; padding: 1px 4px; border-radius: 12px;
  background: #ce252d; color: white; text-align: center;
  font-size: .72rem; line-height: 16px; font-weight: 700;
}
.avatar {
  display: grid; place-items: center; flex: 0 0 44px; height: 44px;
  border-radius: 8px; background: #d9f1e4; color: #14633e; font-weight: 700;
}
.conversation-detail { display: none; }
.in-conversation .conversation-list { display: none; }
.in-conversation .conversation-detail { display: block; }
.conversation, .composer { background: #f7f7f7; }
#backToChats { font-size: 1.45rem; line-height: 1; }
#messages { background: #ededed; }
.bubble { border-color: #e5e5e5; }
.mine { background: #95ec69; border-color: #8cde63; }

/* Keep the composer visible as the app window changes size. */
body.conversation-open {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
body.conversation-open .topbar { flex: 0 0 auto; }
body.conversation-open main {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  width: 100%;
}
.in-conversation.chat-panel { display: flex; flex: 1; min-height: 0; }
.in-conversation .conversation-detail { display: flex; flex: 1; flex-direction: column; min-width: 0; }
.in-conversation #messages { flex: 1; height: auto; min-height: 0; }
.in-conversation .conversation, .in-conversation .composer { flex: 0 0 auto; }
.android-app .topbar { padding-right: max(60px, calc((100vw - 760px) / 2)); }
@media (max-width: 600px) {
  body.conversation-open main { padding: 0; }
  .in-conversation.chat-panel { border: 0; border-radius: 0; }
}
.chat-list-header { display:flex; align-items:center; justify-content:space-between; padding:8px 12px; border-bottom:1px solid var(--line); }
.chat-list-header h2 { border:0; padding:0; }
#groupDialog { width:min(92vw,420px); max-height:80vh; border:1px solid var(--line); border-radius:16px; padding:16px; color:var(--ink); }
#groupDialog::backdrop { background:#0006; }
#groupMembers { max-height:32vh; overflow:auto; }
.bubble audio, .voice-draft audio { display:block; width:min(235px,100%); max-width:100%; }
.voice-draft { padding:8px 12px; background:#f7f7f7; }
.composer #recordVoice { padding-inline:8px; }
#profileDialog { width:min(92vw,420px); max-height:85vh; border:1px solid var(--line); border-radius:16px; padding:16px; color:var(--ink); }
#profileDialog::backdrop { background:#0006; }
#profilePreview { margin:12px 0; }
#profilePreview .avatar { width:64px; height:64px; font-size:1.4rem; }
.avatar { overflow:hidden; }
.avatar img { width:100%; height:100%; object-fit:cover; }
#profileStatus { color:#9a3625; }
#profileStatus:empty { display:none; }
.chat-list-header .row { gap:6px; }
.chat-list-header button { padding-inline:9px; }
.bubble .sender-label { display:flex; align-items:center; gap:6px; }
.sender-label .avatar { flex:0 0 18px; height:18px; border-radius:4px; font-size:.65rem; }
.selection-bar { padding:8px 10px; background:#fff; border-top:1px solid var(--line); flex:0 0 auto; }
.selection-bar output { display:block; color:var(--brand-dark); overflow-wrap:anywhere; }
.selection-bar .row { flex-wrap:wrap; margin-top:5px; }
.selection-bar button, .call-actions button { padding-inline:8px; }
.message-select { float:right; width:18px; height:18px; margin:2px 0 4px 8px; }
#membersDialog { width:min(92vw,420px); max-height:80vh; border:1px solid var(--line); border-radius:16px; padding:16px; }
#membersDialog::backdrop { background:#0006; }
#membersList { max-height:50vh; overflow:auto; list-style:none; padding:0; }
#membersList li { display:flex; align-items:center; gap:8px; padding:5px 0; overflow-wrap:anywhere; }
#membersList .avatar { flex-basis:32px; height:32px; }
#groupSumDialog { width:min(92vw,420px); max-height:80vh; border:1px solid var(--line); border-radius:16px; padding:16px; }
#groupSumDialog::backdrop { background:#0006; }
#groupSumResult { overflow-wrap:anywhere; }
.dismiss-notice { min-height:28px; padding:2px 7px; margin-inline-start:8px; font-size:.75rem; }
#membersList li button { margin-inline-start:auto; min-height:32px; padding:3px 8px; } #addMemberForm select { flex:1; margin:0; } #memberStatus { color:#9a3625; } #memberStatus:empty { display:none; }
.message-time { display:block; margin-top:4px; color:var(--muted); font-size:.72rem; text-align:end; white-space:nowrap; font-variant-numeric:tabular-nums; }
#passwordDialog { width:min(92vw,420px); max-height:85vh; border:1px solid var(--line); border-radius:16px; padding:16px; color:var(--ink); }
#passwordDialog::backdrop { background:#0006; }
#passwordStatus { color:#9a3625; }
#passwordStatus:empty { display:none; }
.account-actions { margin:0; gap:5px; }
.account-actions button { padding-inline:8px; }
.composer #recordVoice { flex:0 0 44px; padding:0; } #recordVoice svg { display:block; width:22px; height:22px; margin:auto; }
.voice-convert { min-height:30px; padding:3px 8px; margin-top:6px; font-size:.8rem; } .voice-transcript { margin:6px 0 0; padding-top:6px; border-top:1px solid var(--line); }
#messageMenu { width:min(92vw,420px); max-height:80vh; border:1px solid var(--line); border-radius:16px; padding:16px; color:var(--ink); }
#messageMenu::backdrop { background:#0006; }
#messageMenuActions { display:flex; flex-wrap:wrap; gap:8px; margin:12px 0; }
#forwardForm select { flex:1; margin:0; }
#messageMenuStatus { color:#9a3625; }
#messageMenuStatus:empty { display:none; }
.message-more { min-height:26px; padding:0 7px; margin-top:4px; font-size:.9rem; }
.bubble:has(.message-more) { touch-action:pan-y; -webkit-user-select:none; user-select:none; }
.copy-fallback { display:block; width:100%; min-height:75px; margin-top:10px; font:inherit; }
#deviceBlacklist { border-top:1px solid var(--line); margin-top:16px; padding-top:12px; } #deviceBlacklist summary { cursor:pointer; margin-bottom:8px; } #blockedDevices { padding:0; list-style:none; } #blockedDevices li { display:flex; justify-content:space-between; align-items:center; gap:8px; margin:8px 0; overflow-wrap:anywhere; }
.chat-image { cursor:zoom-in; }
#imageViewer { width:100%; height:100%; max-width:none; max-height:none; margin:0; padding:52px 8px 12px; border:0; background:#101010f5; }
#imageViewer[open] { display:grid; place-items:center; }
#fullImage { display:block; width:100%; height:100%; min-height:0; max-width:100%; object-fit:contain; }
#closeImageViewer { position:absolute; top:8px; right:8px; min-width:44px; padding:0; font-size:1.5rem; background:#333; color:#fff; }
#typingStatus { flex:0 0 auto; padding:2px 12px; background:#f7f7f7; color:var(--muted); font-size:.82rem; }
