:root {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #29231f;
  background: #eee7de;
  --paper: #faf6ef;
  --surface: #fffdf9;
  --line: #e7dfd4;
  --soft: #f1ebe3;
  --accent: #92521f;
  --accent-hover: #743d14;
  --ink-muted: #675d54;
  --bubble: #fbe8c8;
  --error: #a12924;
  --viewport-height: 100vh;
}
@supports (height: 100dvh) { :root { --viewport-height: 100dvh; } }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .6; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, p { margin: 0; }
input, textarea { min-width: 0; font-size: 16px; }
input::placeholder, textarea::placeholder { color: var(--ink-muted); }
.primary {
  display: inline-flex; justify-content: center; align-items: center; gap: 7px;
  min-height: 44px; padding: 8px 16px; border: 0; border-radius: 12px;
  background: var(--accent); color: #fff; font-weight: 650;
}
.primary:hover:not(:disabled) { background: var(--accent-hover); }
.plain { border: 0; background: transparent; color: var(--accent); min-height: 44px; padding: 4px; }
.error { color: var(--error); font-size: .875rem; margin-top: 8px; }
.icon {
  display: inline-block; flex: none; width: 24px; height: 24px; background: currentColor;
  -webkit-mask: var(--glyph) center / contain no-repeat; mask: var(--glyph) center / contain no-repeat;
}
.icon-search { --glyph: url("/static/icons/search.png"); }
.icon-plus { --glyph: url("/static/icons/plus.png"); }
.icon-back { --glyph: url("/static/icons/back.png"); }
.icon-smile { --glyph: url("/static/icons/smile.png"); }
.icon-clip { --glyph: url("/static/icons/clip.png"); }
.icon-photo { --glyph: url("/static/icons/photo.png"); }
.icon-video { --glyph: url("/static/icons/video.png"); }
.icon-close { --glyph: url("/static/icons/close.png"); }
.icon-button {
  display: grid; flex: none; place-items: center; width: 44px; height: 44px;
  padding: 0; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--accent);
}
.icon-button:hover, .icon-button[aria-expanded="true"] { background: var(--soft); }

.login { min-height: var(--viewport-height); padding: 24px; display: grid; place-items: center; background: var(--paper); }
.login-card { width: min(100%, 392px); padding: clamp(20px, 6vw, 36px); border-radius: 20px; background: var(--surface); border: 1px solid var(--line); }
.logo { display: block; margin-bottom: 14px; border-radius: 14px; }
.login h1 { font-size: 30px; }
.login form { display: grid; gap: 9px; margin-top: 24px; }
.login label, .new-form label { font-size: 14px; font-weight: 600; }
.login input, .new-form input { height: 46px; width: 100%; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); }
.login label:not(:first-child) { margin-top: 5px; }
.login .primary { margin-top: 10px; }
.login-note { margin-top: 17px; font-size: 13px; color: var(--ink-muted); }

#app {
  display: grid; grid-template-columns: clamp(282px, 32%, 355px) minmax(0, 1fr);
  max-width: 1260px; height: calc(var(--viewport-height) - 40px); margin: 20px auto;
  background: var(--paper); border: 1px solid var(--line); border-radius: 18px; overflow: hidden;
}
.sidebar, .room { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; }
.sidebar { border-right: 1px solid var(--line); background: var(--paper); }
.inbox-header { display: grid; place-items: center; min-height: 70px; padding: 12px 16px; }
.inbox-header h1 { font-size: 27px; font-weight: 750; letter-spacing: .03em; }
.search-wrap { display: flex; align-items: center; gap: 8px; margin: 2px 16px 8px; padding: 0 12px; border-radius: 14px; background: var(--soft); color: var(--ink-muted); }
.search-wrap .icon { width: 21px; height: 21px; }
.search-wrap input { width: 100%; min-height: 45px; padding: 4px 0; border: 0; background: none; }
.search-wrap:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.search-wrap input:focus-visible { outline: none; }
.conversations { min-height: 0; flex: 1; overflow: auto; padding: 0 16px; }
.conversation {
  width: 100%; min-height: 78px; display: grid; grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center; gap: 11px; padding: 10px 1px; border: 0;
  border-bottom: 1px solid var(--line); text-align: left; background: transparent;
}
.conversation:focus-visible { outline-offset: -2px; }
.conversation:hover, .conversation[aria-current="true"] { background: var(--soft); }
.avatar { width: 48px; height: 48px; display: grid; place-items: center; flex: none; border-radius: 50%; background: #efdcbe; color: #714317; font-size: 19px; font-weight: 700; }
.avatar[data-tone="1"] { background: #e6dfcd; color: #574a2b; }
.avatar[data-tone="2"] { background: #f2ddd6; color: #7d4535; }
.avatar[data-tone="3"] { background: #e2e7d5; color: #465337; }
.conversation strong, .conversation p, .account-name, #peer-name { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation strong { font-size: 17px; }
.conversation p { margin-top: 4px; font-size: 14px; color: var(--ink-muted); }
.conversation time { align-self: start; padding-top: 6px; font-size: 12px; color: var(--ink-muted); white-space: nowrap; }
.list-note { margin: 25px 3px; color: var(--ink-muted); font-size: 14px; }
.sidebar-footer { padding: 10px 16px max(3px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.new-chat { display: flex; width: 100%; min-height: 49px; }
.new-chat .icon { width: 20px; height: 20px; }
.new-form { margin-bottom: 10px; }
.find-actions { display: flex; gap: 8px; margin-top: 7px; }
.find-actions button { white-space: nowrap; }
.account-actions { display: flex; gap: 10px; align-items: center; color: var(--ink-muted); font-size: 12px; padding-inline: 2px; }
.account-name { margin-right: auto; min-width: 0; }
.connection { white-space: nowrap; }
.connection[data-offline="true"] { color: var(--error); }

.chat { min-height: 0; min-width: 0; background: #fbf7f1; }
.empty { display: grid; height: 100%; place-items: center; text-align: center; padding: 24px; }
.empty h2 { font-size: 23px; margin-bottom: 8px; }
.empty p { color: var(--ink-muted); font-size: 15px; }
.room-header {
  position: relative; flex: none; display: grid; place-items: center;
  min-height: 68px; padding: 8px 58px; border-bottom: 1px solid var(--line); background: var(--paper);
}
#peer-name { max-width: 100%; font-size: 21px; font-weight: 750; }
.back { display: none; position: absolute; left: 8px; top: 50%; transform: translateY(-50%); border-color: transparent; background: none; color: #29231f; }
.back .icon { width: 30px; height: 30px; }
.messages { min-height: 0; flex: 1; overflow: auto; overscroll-behavior: contain; padding: 14px clamp(16px, 7vw, 72px) 20px; }
#message-list { display: flow-root; }
.day-divider { display: flex; align-items: center; gap: 13px; width: 100%; margin: 18px 0; color: var(--ink-muted); text-align: center; font-size: 13px; }
.day-divider:before, .day-divider:after { content: ""; flex: 1; height: 1px; background: var(--line); }
.message { display: flex; gap: 9px; align-items: flex-start; margin: 0 0 14px; }
.message.mine { flex-direction: row-reverse; }
.message .avatar { width: 34px; height: 34px; font-size: 14px; }
.message-body { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; max-width: min(calc(100% - 46px), 520px, 78%); gap: 4px; }
.mine .message-body { align-items: flex-end; }
.bubble { max-width: 100%; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); padding: 9px 12px; font-size: 16px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.mine .bubble { background: var(--bubble); border-color: var(--bubble); }
.message time { color: var(--ink-muted); font-size: 11px; padding-inline: 3px; }
.bubble.media { padding: 4px; line-height: normal; overflow: hidden; }
.chat-image, .chat-video { display: block; max-width: min(100%, 340px); max-height: 380px; border-radius: 11px; }
.chat-video { width: min(100%, 340px); min-width: 0; background: #2c251e; }
.media-fallback { display: block; color: var(--accent); padding: 8px; font-size: 14px; }
.load-more { display: block; min-height: 44px; margin: 0 auto 8px; padding: 6px 13px; border: 0; border-radius: 8px; background: var(--soft); color: var(--accent); font-size: 13px; }
.room-note { text-align: center; margin: 16px 0; color: var(--ink-muted); font-size: 14px; }

.composer { flex: none; padding: 10px max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); background: var(--paper); border-top: 1px solid var(--line); }
#send-form { display: flex; align-items: flex-end; gap: 7px; margin: auto; max-width: 860px; }
#content { display: block; flex: 1; min-height: 44px; max-height: 96px; padding: 10px 11px; line-height: 22px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); resize: none; overflow-y: auto; }
.text-send { flex: none; padding-inline: 14px; }
.send-feedback { display: flex; align-items: center; gap: 8px; max-width: 860px; margin: 0 auto; }
.send-status { margin: 6px 0 0; color: var(--ink-muted); font-size: 13px; }
.send-feedback .plain { font-size: 13px; }
.send-status[data-error="true"], #upload-status[data-error="true"] { color: var(--error); }
.attachment-panel, .emoji-panel { display: grid; gap: 8px; max-width: 860px; margin: 10px auto 0; }
.attachment-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.attachment-option { display: grid; justify-items: center; align-content: center; gap: 7px; min-height: 96px; padding: 8px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); font-size: 15px; font-weight: 650; }
.attachment-option:hover { background: var(--soft); }
.attachment-option .icon { width: 31px; height: 31px; color: var(--accent); }
.emoji-panel { grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 1px; }
.emoji-panel button { min-height: 42px; min-width: 0; padding: 0; border: 0; border-radius: 8px; background: transparent; font-size: 24px; }
.emoji-panel button:hover { background: var(--soft); }
.attachment-preview { max-width: 860px; margin: 0 auto 9px; padding: 8px 11px; background: var(--surface); border: 1px solid var(--line); border-radius: 13px; }
.preview-header, .preview-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.preview-header > div, #upload-status { min-width: 0; }
#preview-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-muted); font-size: 12px; margin-top: 2px; }
.preview-header .icon-button { border-color: transparent; }
.preview-media { display: flex; justify-content: center; padding: 5px 0; min-height: 8px; }
.preview-media img, .preview-media video { max-width: 100%; max-height: min(148px, 21vh); border-radius: 10px; }
#upload-progress { width: 100%; accent-color: var(--accent); }
#upload-status { color: var(--ink-muted); font-size: 13px; }
.preview-footer .primary { flex: none; }

@media (min-width: 701px) and (max-width: 1300px) { #app { margin-inline: 20px; } }
@media (max-width: 700px) {
  body { background: var(--paper); }
  #app { display: block; height: var(--viewport-height); margin: 0; border: 0; border-radius: 0; }
  .sidebar { width: 100%; border-right: 0; }
  .inbox-header { padding-top: max(13px, env(safe-area-inset-top)); min-height: 61px; }
  .chat { display: none; height: 100%; }
  .in-room .sidebar { display: none; }
  .in-room .chat { display: block; }
  .room-header { min-height: 58px; padding-top: max(8px, env(safe-area-inset-top)); }
  .back { display: grid; }
  .messages { padding: 9px max(12px, env(safe-area-inset-right)) 14px max(12px, env(safe-area-inset-left)); }
  .message-body { max-width: min(calc(100% - 44px), 78%); }
  .bubble { padding: 8px 11px; }
  .attachment-option { min-height: 86px; }
  .composer { padding-top: 8px; }
  .preview-media img, .preview-media video { max-height: min(124px, 19vh); }
}
@media (max-width: 350px) {
  .composer { padding-inline: 6px; }
  #send-form { gap: 4px; }
  .text-send { padding-inline: 10px; }
}
