:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  color: #272238;
  background: #f7f6fa;
  font-size: 14px;
  --ink: #272238;
  --quiet: #625c73;
  --line: #e7e3ee;
  --surface: #fff;
  --accent: #5c42ca;
  --accent-dark: #4e36b2;
  --accent-soft: #eee9ff;
  --danger: #a22550;
  --radius: 12px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body, h1, h2, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .56; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
::selection { color: #271959; background: #ded3ff; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.primary, .secondary, .text-button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: none;
  font-weight: 650;
  white-space: nowrap;
}

.primary { color: #fff; background: var(--accent); }
.primary:not(:disabled):hover { background: var(--accent-dark); }
.secondary { color: var(--accent-dark); border-color: #e2d9fc; background: #f7f3ff; }
.secondary:not(:disabled):hover { background: var(--accent-soft); }
.text-button { color: var(--accent-dark); }
.text-button:not(:disabled):hover { background: var(--accent-soft); }
.error { color: var(--danger); line-height: 1.5; overflow-wrap: anywhere; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 17px;
  font-weight: 770;
  letter-spacing: .08em;
}

.brand-mark {
  display: inline-grid;
  position: relative;
  flex: none;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 11px;
  background: linear-gradient(145deg, #8468ec, #5a3fc5);
  box-shadow: inset 0 0 0 1px #ffffff22, 0 4px 9px #5233a233;
}

.brand-mark::before, .brand-mark::after { position: absolute; content: ""; }
.brand-mark::before { width: 49%; height: 38%; border: 2px solid #fff; border-radius: 45% 45% 45% 12%; }
.brand-mark::after { width: 11%; aspect-ratio: 1; border-radius: 50%; background: #fff; }

.login {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px;
  background:
    radial-gradient(ellipse at 16% 22%, #59447f 0, transparent 37%),
    radial-gradient(ellipse at 89% 88%, #352263 0, transparent 42%),
    #221b38;
}

.login-card {
  width: min(100%, 416px);
  padding: clamp(23px, 5vw, 38px);
  border: 1px solid #f1ebfa;
  border-radius: 22px;
  background: var(--surface);
  box-shadow: 0 18px 60px #10091f65;
}

.login-card h1 { margin: 24px 0 18px; font-size: clamp(22px, 5vw, 27px); }
.login-card > p { color: var(--quiet); }
.login-card form { display: grid; gap: 10px; }
.login-card label, .field > span { font-weight: 650; }
.login-card button { margin-top: 8px; min-height: 45px; }
.login-card input + label { margin-top: 5px; }

input:not([type="checkbox"]), textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid #d9d3e4;
  border-radius: 9px;
  background: var(--surface);
  padding: 10px 12px;
}

input:not([type="checkbox"]):focus-visible, textarea:focus-visible {
  outline-offset: 1px;
}

.search { min-height: 42px; }
.inbox input.search { background: #f8f7fb; }
input::placeholder, textarea::placeholder { color: var(--quiet); opacity: 1; }

.workspace {
  display: grid;
  grid-template-columns: clamp(268px, 26vw, 338px) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.inbox, .conversation {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.inbox { background: var(--surface); border-right: 1px solid var(--line); }
.inbox-header { padding: 23px 21px 12px; }
.inbox-header h1 { margin: 22px 0 12px; font-size: 26px; }
.inbox-actions { display: flex; gap: 8px; margin-bottom: 12px; }
.inbox-actions button { flex: 1; }
.inbox-feedback { padding: 7px 21px; color: var(--quiet); line-height: 1.5; overflow-wrap: anywhere; }
.inbox-retry { align-self: start; margin-left: 7px; }

.conversation-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 3px 10px 10px;
}

.conversation-list li + li { margin-top: 3px; }

.conversation-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 10px;
  min-height: 61px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  text-align: start;
}

.conversation-item:hover { background: #f8f6fc; }
.conversation-item[aria-current="true"] { border-color: #e9e0ff; background: #f1edff; }
.conversation-item:focus-visible { outline-offset: -2px; }
.avatar {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 39px;
  height: 39px;
  border-radius: 12px;
  color: #4d358e;
  background: #eae2fe;
  font-size: 13px;
  font-weight: 750;
}

.group-avatar { background: #deedf1; color: #285a67; }
.conversation-copy, .profile-copy, .person-copy, .conversation-heading { flex: 1; min-width: 0; }
.conversation-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.conversation-top time { flex: none; color: var(--quiet); font-size: 11px; }
.conversation-top strong, .conversation-preview, .profile-copy > *, .person-copy > *, .conversation-heading h2 {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-preview { margin-top: 4px; color: var(--quiet); font-size: 12px; }

.inbox-footer {
  padding: 10px 16px max(13px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.connection {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 7px;
  padding-inline: 4px;
  color: var(--quiet);
  font-size: 12px;
}

.connection::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #887d9c;
}
.connection[data-state="online"]::before { background: #278259; }
.connection[data-state="offline"]::before { background: #ac6130; }
.profile { display: flex; align-items: center; gap: 10px; }
.profile-copy span { color: var(--quiet); font-size: 12px; }
.profile .text-button { padding-inline: 8px; }

.welcome {
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 24px;
  text-align: center;
  background: radial-gradient(ellipse at 50% 43%, #f0e9ff, #f8f7fb 52%);
}
.welcome-card { display: grid; gap: 12px; justify-items: center; }
.welcome .brand-mark { width: 54px; height: 54px; border-radius: 17px; }
.welcome h2 { margin-top: 6px; font-size: 20px; }
.welcome p { color: var(--quiet); }

.conversation-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 72px;
  padding: 10px clamp(14px, 2.3vw, 30px);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.conversation-heading h2 { font-size: 17px; }
.conversation-heading p { padding-top: 3px; color: var(--quiet); font-size: 12px; }
.chat-connection { display: none; }
.mobile-back { display: none; }

.feed {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overflow-anchor: none;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.feed:focus-visible { outline-offset: -3px; }
.history-controls {
  width: min(100%, 890px);
  min-height: 10px;
  margin-inline: auto;
  padding: 8px 14px 0;
  text-align: center;
}
.history-status { margin-top: 9px; color: var(--quiet); line-height: 1.5; overflow-wrap: anywhere; }
.message-list { width: min(100%, 890px); margin-inline: auto; padding: 13px clamp(13px, 2.5vw, 28px) 20px; }
.message { display: flex; align-items: start; gap: 9px; margin-bottom: 16px; }
.message:last-child { margin-bottom: 0; }
.message.own { flex-direction: row-reverse; }
.message .avatar { width: 32px; height: 32px; border-radius: 10px; font-size: 11px; }
.message-copy { min-width: 0; max-width: min(76%, 580px); }
.message.own .message-copy { display: grid; justify-items: end; }
.message-meta { display: flex; flex-wrap: wrap; gap: 3px 7px; align-items: baseline; color: var(--quiet); font-size: 12px; }
.message.own .message-meta { justify-content: flex-end; }
.message-author { font-weight: 650; overflow-wrap: anywhere; }
.message-text {
  margin-top: 4px;
  border: 1px solid var(--line);
  border-radius: 3px 13px 13px 13px;
  background: var(--surface);
  padding: 9px 12px;
  max-width: 100%;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message.own .message-text { border-color: #ded4fa; border-radius: 13px 3px 13px 13px; background: var(--accent-soft); }
.delivery { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: end; gap: 3px; color: var(--quiet); font-size: 12px; text-align: right; }
.delivery-label { margin-top: 3px; overflow-wrap: anywhere; }
.delivery:has(button:not([hidden])) { color: var(--danger); }
.delivery button { padding-inline: 8px; min-height: 32px; }

.composer {
  width: min(100%, 890px);
  margin-inline: auto;
  padding: 9px clamp(12px, 2vw, 24px) max(12px, env(safe-area-inset-bottom));
}

.composer textarea { display: block; max-height: 26dvh; min-height: 58px; resize: vertical; }
.composer .error { margin-bottom: 7px; }
.composer-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 7px; }
.composer-footer p { color: var(--quiet); font-size: 11px; }
.composer-footer .primary { margin-inline-start: auto; min-width: 78px; }

.people-dialog {
  width: min(calc(100% - 24px), 495px);
  max-height: min(88dvh, 710px);
  padding: 16px 19px 20px;
  border: 1px solid var(--line);
  border-radius: 17px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 14px 40px #1f122d44;
}

.people-dialog::backdrop { background: #22153280; }
.dialog-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.dialog-header h2 { font-size: 19px; }
#people-form { display: grid; gap: 9px; }
.field { display: grid; gap: 6px; }
.people-list { min-height: 0; max-height: 30dvh; overflow: auto; overscroll-behavior: contain; }
#group-members { max-height: 23dvh; }
.person + .person { margin-top: 3px; }
#group-members .person, .person-action { display: flex; align-items: center; gap: 9px; padding: 5px 7px; }
.person-action {
  width: 100%;
  min-height: 50px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: #f8f7fb;
  text-align: start;
  cursor: pointer;
}
.person-action:hover { background: var(--accent-soft); }
.person-action:focus-visible { outline-offset: -3px; }
.person-action .avatar, #group-members .avatar { width: 35px; height: 35px; }
.person-copy span, .person-role, .dialog-status { color: var(--quiet); font-size: 12px; }
.person-role { white-space: nowrap; }
.person-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.person-action input[type="checkbox"] { width: 17px; height: 17px; margin: 0; flex: none; accent-color: var(--accent); }
#people-submit { justify-self: end; }

@media (max-width: 680px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .workspace:not(.chat-open) .welcome, .workspace.chat-open .inbox { display: none; }
  .inbox { border: 0; }
  .mobile-back { display: inline-block; padding-inline: 6px; }
  .conversation-header { min-height: 62px; gap: 7px; padding-inline: 9px; }
  .conversation-header > .avatar { width: 33px; height: 33px; font-size: 11px; border-radius: 9px; }
  .chat-connection { display: block; }
  .conversation-header .secondary { padding-inline: 8px; }
  .composer textarea, .login input, .people-dialog input:not([type="checkbox"]), .inbox .search { font-size: 16px; }
  .composer-footer p { display: none; }
}
