:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #182e2c;
  background: #edf3ef;
  --ink: #142b2a;
  --muted: #526762;
  --line: #d5e0dc;
  --accent: #116957;
  --soft: #e3f3e9;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, input, textarea { font: inherit; }
button, .file {
  border: 0; border-radius: 10px; padding: .65rem .85rem; min-height: 44px;
  cursor: pointer; background: var(--accent); color: white; white-space: nowrap;
}
button:disabled { opacity: .55; cursor: default; }
button:focus-visible, .file:focus-within { outline: 2px solid #136c5b; outline-offset: 3px; }
.secondary { background: var(--soft); color: var(--ink); }
.quiet { background: transparent; color: inherit; }
input, textarea {
  width: 100%; padding: .65rem .75rem; border: 1px solid var(--line); border-radius: 10px;
  min-width: 0; color: var(--ink); background: white;
}
label { display: grid; gap: .35rem; font-weight: 600; }
form { display: grid; gap: .75rem; }
h1, h2, h3, p { margin: 0; }
.auth {
  width: min(400px, calc(100% - 32px)); margin: clamp(16px, 12vh, 120px) auto;
  background: white; padding: clamp(20px, 6vw, 36px); border: 1px solid var(--line);
  border-radius: 24px; display: grid; gap: 1rem;
}
.auth p, .empty p { color: var(--muted); }
.app-icon { border-radius: 22%; }
.hint { background: var(--soft); padding: .65rem; border-radius: 10px; }
.workspace { display: grid; grid-template-columns: minmax(230px, 300px) minmax(0, 1fr); height: 100dvh; }
.sidebar { background: white; border-right: 1px solid var(--line); min-height: 0; display: flex; flex-direction: column; }
header, .side-title, .actions, .compose-row { display: flex; gap: .5rem; align-items: center; }
.sidebar header { justify-content: space-between; color: white; background: var(--ink); padding: .7rem 1rem; }
.header-actions { display: flex; align-items: center; gap: .25rem; min-width: 0; }
.header-actions button { padding-inline: .5rem; }
#profile-open { display: flex; align-items: center; gap: .45rem; min-width: 0; }
.profile-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.conversation-search {
  display: flex; align-items: center; gap: .55rem; flex: none;
  margin: .7rem .75rem .2rem; padding: 0 .65rem; border: 1px solid var(--line);
  border-radius: 12px; background: #f4f8f6;
}
.conversation-search:focus-within { border-color: var(--accent); }
.conversation-search-icon {
  position: relative; flex: none; width: 13px; height: 13px;
  border: 1.8px solid var(--muted); border-radius: 50%;
}
.conversation-search-icon::after {
  content: ""; position: absolute; width: 6px; height: 2px; right: -5px; bottom: -2px;
  border-radius: 2px; background: var(--muted); transform: rotate(45deg);
}
.conversation-search input { flex: 1; min-width: 0; border: 0; background: transparent; padding: .64rem .2rem; outline: none; }
.conversation-search input::-webkit-search-cancel-button { appearance: none; }
.conversation-search button { padding: .38rem .25rem; }
#conversation-results-status { padding: .6rem 1rem .25rem; font-size: .88rem; }
.view-switch {
  flex: none; display: grid; grid-template-columns: 1fr 1fr; gap: .5rem;
  padding: .35rem .75rem max(.35rem, env(safe-area-inset-bottom)); border-top: 1px solid var(--line);
  background: #f6faf8;
}
.view-switch button {
  position: relative; display: grid; place-content: center; justify-items: center; gap: .2rem;
  min-height: 58px; padding: .3rem .6rem; color: var(--muted); background: transparent;
  font-size: .85rem; font-weight: 600; border-radius: 12px;
}
.view-switch button[aria-pressed="true"] { color: var(--accent); background: var(--soft); }
.view-switch .badge { position: absolute; top: .25rem; left: calc(50% + .65rem); }
.view-icon { position: relative; display: block; width: 26px; height: 24px; }
.view-icon::before, .view-icon::after { content: ""; position: absolute; }
.friend-icon::before { width: 9px; height: 9px; top: 0; left: 9px; border: 2px solid; border-radius: 50%; }
.friend-icon::after { width: 19px; height: 9px; bottom: 0; left: 4px; border: 2px solid; border-radius: 8px 8px 3px 3px; }
.group-icon::before, .group-icon::after { width: 15px; height: 12px; border: 2px solid; border-radius: 5px 5px 5px 1px; }
.group-icon::before { top: 1px; right: 0; }
.group-icon::after { bottom: 2px; left: 0; background: #f6faf8; }
.view-switch button[aria-pressed="true"] .group-icon::after { background: var(--soft); }
.sidebar-panel { display: flex; flex: 1; flex-direction: column; min-height: 0; }
.side-title { justify-content: space-between; padding: .8rem 1rem; }
.side-title h1 { font-size: 1.12rem; }
.group-actions { display: flex; gap: .3rem; }
.group-actions button { padding-inline: .55rem; }
.sidebar-empty { color: var(--muted); padding: .25rem 1rem 1rem; line-height: 1.5; }
nav { overflow: auto; display: grid; align-content: start; gap: .35rem; padding: 0 .75rem 1rem; }
nav button { background: transparent; color: var(--ink); display: flex; align-items: center; text-align: left; gap: .65rem; }
nav button[aria-current="true"], nav button:hover { background: var(--soft); }
nav .group-name, .chat-header h2 { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--accent); color: white; border-radius: 999px; padding: .15rem .45rem; font-size: .78rem; }
#friend-count { margin-left: .35rem; }
.conversation-kind { font-size: .78rem; color: var(--muted); }
.empty { display: grid; place-content: center; justify-items: center; gap: .8rem; text-align: center; padding: 1rem; }
.chat { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.chat-header { padding: .65rem 1rem; background: white; border-bottom: 1px solid var(--line); }
.chat-header h2 { white-space: nowrap; font-size: 1.12rem; }
#back { display: none; }
.announcement { padding: .7rem 1rem; background: #fff8dd; white-space: pre-wrap; overflow: auto; overflow-wrap: anywhere; max-height: 22vh; }
.history { flex: 1; min-height: 0; overflow: auto; padding: .9rem clamp(.7rem, 3vw, 2rem); overflow-anchor: none; }
.history { display: flex; flex-direction: column; }
.history > * { flex: none; }
#messages { margin-top: auto; }
#older { display: block; margin: 0 auto .75rem; }
#message-search { display: flex; align-items: end; gap: .45rem; margin: .65rem 0; }
#message-search label { flex: 1; }
#search-status { color: var(--muted); }
#search-results article { padding: .55rem .1rem; border-bottom: 1px solid var(--line); }
#search-results small { color: var(--muted); }
#search-results p { white-space: pre-wrap; overflow-wrap: anywhere; }
#search-more { margin-top: .6rem; }
.entry { display: flex; gap: .55rem; margin-bottom: .85rem; align-items: flex-start; }
.entry.mine { flex-direction: row-reverse; }
.avatar { flex: none; display: inline-grid; place-items: center; width: 38px; height: 38px; object-fit: cover; border-radius: 12px; background: #d7ebe0; color: var(--ink); font-size: .85rem; }
header .avatar { margin-inline-end: .35rem; width: 32px; height: 32px; vertical-align: middle; }
.entry .content { min-width: 0; max-width: min(80%, 620px); }
.entry small { display: block; color: var(--muted); margin-bottom: .25rem; overflow-wrap: anywhere; }
.mine small { text-align: right; }
.bubble { padding: .6rem .75rem; border-radius: 2px 14px 14px 14px; background: white; white-space: pre-wrap; overflow-wrap: anywhere; }
.mine .bubble { background: #d7eedf; border-radius: 14px 2px 14px 14px; }
.delivery-state { display: flex; align-items: center; justify-content: flex-end; gap: .4rem; margin-top: .2rem; color: var(--muted); font-size: .78rem; }
.delivery-state button { min-height: 36px; padding: .25rem .55rem; }
.bubble img { display: block; max-width: 100%; max-height: 290px; border-radius: 8px; }
.bubble p + img { margin-top: .4rem; }
.compose { padding: .65rem 1rem max(.65rem, env(safe-area-inset-bottom)); background: white; border-top: 1px solid var(--line); }
.compose-row input { flex: 1; }
.file { position: relative; display: inline-grid; place-items: center; background: var(--soft); color: var(--ink); }
.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.emoji { display: flex; flex-wrap: wrap; gap: .15rem; }
#attachment-info { overflow-wrap: anywhere; }
#jump { align-self: center; margin: .2rem; }
dialog { width: min(480px, calc(100% - 24px)); max-height: 86dvh; border: 1px solid var(--line); color: inherit; border-radius: 18px; padding: 1.15rem; }
dialog::backdrop { background: #142b2a77; }
.admin-dialog { width: min(590px, calc(100% - 24px)); }
.admin-switch, .admin-actions { display: flex; flex-wrap: wrap; gap: .3rem; }
.admin-switch { margin-block: .6rem; }
.admin-switch button[aria-pressed="true"] { color: white; background: var(--accent); }
.admin-search { grid-template-columns: minmax(0, 1fr) auto; align-items: end; }
.admin-empty { color: var(--muted); margin-top: .75rem; }
.admin-row { justify-content: space-between; flex-wrap: wrap; padding-block: .45rem; }
.admin-row-name { flex: 1; min-width: 7rem; overflow-wrap: anywhere; }
.admin-row-name small { display: block; color: var(--muted); margin-top: .2rem; }
dialog header { justify-content: space-between; }
#profile-title:focus { outline: none; }
dialog section, dialog h3 { margin-top: .8rem; }
.conversation-settings { border-top: 1px solid var(--line); padding-top: .75rem; }
#dissolve-group { background: #fce9e8; color: #9b2825; }
.conversation-settings p { color: var(--muted); font-size: .9rem; margin-top: .35rem; }
.friend-code { display: flex; gap: .5rem; align-items: end; margin-bottom: .75rem; }
.friend-code label { flex: 1; min-width: 0; }
.friend-qr, #invite-friends { margin: 0 0 .8rem; border: 1px solid var(--line); padding: .6rem .75rem; border-radius: 12px; }
.friend-qr summary, #invite-friends summary { cursor: pointer; font-weight: 600; padding-block: .4rem; }
.friend-qr img { display: block; margin: .25rem auto; max-width: 100%; object-fit: contain; }
.friend-qr p { color: var(--muted); text-align: center; font-size: .88rem; }
#invite-friends p { color: var(--muted); font-size: .88rem; }
#invite-friends #invite-friends-status { color: var(--accent); }
.qr-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.qr-status { color: var(--muted); font-size: .92rem; }
.device-status { color: var(--muted); margin: .6rem 0; line-height: 1.45; }
.notification-settings { display: grid; gap: .4rem; }
.notification-settings p { color: var(--muted); font-size: .9rem; line-height: 1.45; }
#device-create button, #device-save, #device-restore { margin-top: .6rem; }
.scan-video { display: block; width: 100%; max-height: 36dvh; margin-bottom: .35rem; background: var(--ink); border-radius: 12px; }
#friends-dialog .qr-actions, #push-offer p { margin-bottom: .75rem; }
#owner-tools { display: grid; gap: .75rem; }
.actions { justify-content: flex-end; flex-wrap: wrap; }
.check { display: flex; align-items: center; }
.check input { width: auto; }
ul { list-style: none; padding: 0; margin: .4rem 0; }
li { display: flex; align-items: center; gap: .5rem; padding: .25rem 0; border-bottom: 1px solid var(--line); }
li span.member-name { flex: 1; overflow-wrap: anywhere; }
#status { position: fixed; z-index: 1; top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); background: var(--ink); color: white; padding: .65rem .9rem; border-radius: 10px; width: max-content; max-width: calc(100% - 24px); }
dialog[open] ~ #status { display: none; }
.inline-status { color: var(--accent); padding: .3rem 0; }
@media (max-width: 680px) {
  .workspace { display: flex; flex-direction: column; }
  .workspace.chat-open {
    position: fixed; inset-inline: 0; top: var(--chat-viewport-top, 0px);
    height: var(--chat-viewport-height, 100dvh); overflow: hidden;
  }
  .sidebar, .chat { flex: 1; }
  .workspace.chat-open .sidebar, .empty { display: none; }
  .chat-header, .announcement, .compose { flex-shrink: 0; }
  #back { display: inline-block; }
  .compose { padding-inline: .45rem; }
  .compose-row { gap: .3rem; }
  .compose-row button, .file { padding-inline: .6rem; }
}
