* { box-sizing: border-box; }
:root {
  font-family: 'Segoe UI Variable', 'Segoe UI', system-ui, sans-serif;
  color-scheme: light;
  --canvas: #e9e7f1;
  --panel: #fff;
  --chat: #f7f6fc;
  --ink: #232038;
  --muted: #68647b;
  --line: #e8e5ef;
  --soft: #f3f1f8;
  --selected: #ede8fb;
  --accent: #6544c6;
  --accent-hover: #5435b0;
  --on-accent: #fff;
  --mine: #ece5ff;
  --dot: #dcd6ef;
  --shadow: #29204720;
  --green: #27845f;
}
:root[data-theme=dark] {
  color-scheme: dark;
  --canvas: #151321;
  --panel: #201d30;
  --chat: #191727;
  --ink: #f2effc;
  --muted: #b6afcb;
  --line: #36314a;
  --soft: #2b263f;
  --selected: #382b55;
  --accent: #baa4ff;
  --accent-hover: #cbbcfa;
  --on-accent: #221637;
  --mine: #392a5b;
  --dot: #37314e;
  --shadow: #08060e63;
  --green: #63c99b;
}
body { margin: 0; background: var(--canvas); color: var(--ink); }
button, input, textarea, select { font: inherit; color: inherit; }
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: var(--soft);
  cursor: pointer;
  font-size: .875rem;
  font-weight: 650;
}
button:hover { background: var(--selected); }
button:disabled { opacity: .6; cursor: wait; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.primary { background: var(--accent); color: var(--on-accent); }
.primary:hover { background: var(--accent-hover); }
input, textarea, select {
  width: 100%;
  min-width: 0;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel);
}
::placeholder { color: var(--muted); opacity: 1; }
h1, h2, p { margin: 0; }
small, .quiet { color: var(--muted); }
[hidden] { display: none !important; }
.icon, .mark svg {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.shell {
  width: min(100% - 48px, 1480px);
  height: calc(100dvh - 48px);
  margin: 24px auto;
  display: grid;
  grid-template-columns: clamp(290px, 29vw, 364px) minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: 0 14px 54px var(--shadow);
}
.sidebar {
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 76px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  font-weight: 750;
  letter-spacing: -.035em;
}
.mark {
  width: 38px;
  height: 38px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(145deg, #8767e6, #5938b8);
  color: #fff;
}
.mark svg { width: 23px; height: 23px; }
.sidebar-controls { display: grid; gap: 15px; padding: 20px 16px 9px; }
.room-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
h1 { font-size: 2rem; line-height: 1.1; letter-spacing: -.055em; }
.search-box { position: relative; color: var(--muted); }
.search-box .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); pointer-events: none; }
.search-box input { padding-left: 39px; background: var(--soft); font-size: .875rem; }
.filters { display: flex; flex-wrap: wrap; gap: 4px; }
.filters button { background: transparent; color: var(--muted); min-height: 34px; border-radius: 999px; }
.filters button:hover, .filters button[aria-pressed=true] { background: var(--selected); color: var(--accent); }
.rooms { flex: 1; min-height: 0; overflow: auto; padding: 4px 12px 10px; }
.room, .profile, .contact-nav { justify-content: flex-start; text-align: left; width: 100%; }
.room {
  gap: 11px;
  min-height: 58px;
  padding: 8px 10px;
  margin-bottom: 4px;
  border-radius: 13px;
  background: transparent;
}
.room[aria-current=true] { background: var(--selected); border-color: var(--accent); }
.room-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-star { color: var(--accent); }
.avatar {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 14px;
  background: var(--selected);
  color: var(--accent);
  font-size: .83rem;
  font-weight: 800;
}
.sidebar-footer { display: grid; gap: 5px; padding: 9px 12px 12px; border-top: 1px solid var(--line); }
.contact-nav { gap: 11px; padding-left: 14px; background: transparent; color: var(--muted); }
.profile { gap: 10px; background: var(--soft); }
.profile > span:nth-child(2) { flex: 1; min-width: 0; }
.profile small { display: block; margin-top: 2px; font-weight: 400; }
.profile strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile .icon { color: var(--muted); }
.workspace {
  min-width: 0;
  min-height: 0;
  background-color: var(--chat);
  background-image: radial-gradient(var(--dot) 1px, transparent 1px);
  background-size: 22px 22px;
}
.empty {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  gap: 13px;
  text-align: center;
  padding: 24px;
}
.empty-art { width: 208px; height: 146px; position: relative; margin-bottom: 12px; }
.empty-art::before {
  content: '';
  position: absolute;
  inset: 3px 29px;
  border-radius: 50%;
  background: var(--selected);
}
.empty-art .mark {
  position: absolute;
  inset: 25px auto auto 34px;
  width: 106px;
  height: 75px;
  border-radius: 24px 24px 24px 6px;
  transform: rotate(-12deg);
  box-shadow: 0 12px 28px #4d2d9e46;
}
.empty-art .mark svg { width: 48px; height: 48px; }
.reply-art {
  position: absolute;
  right: 18px;
  bottom: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 84px;
  height: 56px;
  border: 1px solid var(--line);
  border-radius: 18px 18px 5px 18px;
  background: var(--panel);
  transform: rotate(9deg);
  box-shadow: 0 10px 26px var(--shadow);
}
.reply-art i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.empty h2 { font-size: clamp(1.8rem, 4vw, 3rem); line-height: 1.05; letter-spacing: -.055em; }
.empty p { max-width: 31ch; color: var(--muted); line-height: 1.5; }
.empty button { margin-top: 7px; }
.conversation { height: 100%; display: flex; flex-direction: column; }
.chatbar, .compose { display: flex; align-items: center; gap: 9px; background: var(--panel); }
.chatbar { flex: none; min-height: 76px; padding: 12px 22px; border-bottom: 1px solid var(--line); }
.chat-label { flex: 1; min-width: 0; }
.chat-label h2 { font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-label small { font-size: .75rem; }
.chat-label small[data-connected]::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--green);
}
#favorite { min-width: 40px; font-size: 1.2rem; line-height: 1; }
#favorite[aria-pressed=true] { color: var(--accent); background: var(--selected); }
.messages {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 24px clamp(16px, 4vw, 64px);
}
.bubble {
  align-self: flex-start;
  flex: none;
  min-width: 74px;
  max-width: min(82%, 640px);
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 17px 17px 17px 5px;
  background: var(--panel);
  box-shadow: 0 2px 5px var(--shadow);
  overflow-wrap: anywhere;
}
.bubble.mine { align-self: flex-end; background: var(--mine); border-radius: 17px 17px 5px 17px; }
.bubble strong, .bubble time { display: block; font-size: .72rem; color: var(--muted); }
.bubble strong { color: var(--accent); }
.bubble p { margin: 3px 0 4px; white-space: pre-wrap; line-height: 1.45; }
.bubble time { text-align: right; }
.compose { flex: none; padding: 13px 20px; border-top: 1px solid var(--line); }
.compose textarea { resize: vertical; min-height: 44px; max-height: 25vh; line-height: 1.25; background: var(--soft); }
.compose button { min-height: 44px; flex: none; }
.quiet { padding: 13px; text-align: center; font-size: .875rem; }
.messages .quiet { margin: auto; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); }
dialog {
  width: 440px;
  max-width: calc(100vw - 24px);
  max-height: 88dvh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  color: var(--ink);
  padding: clamp(16px, 5vw, 28px);
  box-shadow: 0 24px 80px #100c3055;
}
dialog::backdrop { background: #17112878; backdrop-filter: blur(5px); }
dialog h2 { font-size: 1.7rem; letter-spacing: -.045em; }
dialog label { display: grid; gap: 6px; margin: 15px 0; font-size: .875rem; font-weight: 600; }
dialog input, dialog select { font-weight: 400; }
.actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 15px; }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
#notice {
  position: fixed;
  bottom: 15px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 90vw;
  width: max-content;
  background: var(--ink);
  color: var(--panel);
  padding: 10px 16px;
  border-radius: 12px;
  z-index: 4;
}
#contact-count { border-radius: 15px; background: var(--selected); color: var(--accent); padding: 2px 7px; }
.form-status { color: var(--muted); min-height: 17px; margin: 9px 0; font-size: .83rem; }
#contact-list { display: grid; gap: 8px; max-height: 35dvh; overflow: auto; margin: 10px 0; }
.contact-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; background: var(--soft); border-radius: 12px; padding: 9px 10px; font-size: .875rem; }
.contact-row strong, .contact-row small { display: block; overflow-wrap: anywhere; }
.mobile-back { display: none; }
@media (max-width: 820px) {
  .shell { width: 100%; height: 100dvh; margin: 0; border: 0; border-radius: 0; }
  .chatbar, .compose { padding-inline: 12px; }
}
@media (max-width: 640px) {
  .shell { display: block; }
  .sidebar, .workspace { height: 100%; }
  .sidebar { border: 0; }
  .workspace, .chat-open .sidebar { display: none; }
  .chat-open .workspace, .mobile-back { display: flex; }
  .conversation { width: 100%; }
  .brand { min-height: 64px; padding-inline: 16px; }
  .chatbar { min-height: 62px; padding: 8px; gap: 5px; }
  .chatbar button { min-height: 44px; padding: 6px; font-size: .75rem; }
  .chatbar .avatar, #invite span, #archive span { display: none; }
  #invite, #archive { min-width: 40px; }
  .mobile-back { min-width: 38px; }
  .compose { padding: 9px; padding-bottom: max(9px, env(safe-area-inset-bottom)); }
  .compose input, .compose textarea, dialog input, dialog select, .search-box input { font-size: 1rem; }
  .compose button span { display: none; }
  .compose button { min-width: 46px; }
}

#older {
  flex: none;
  align-self: center;
  margin: 8px 0 0;
  min-height: 34px;
  font-size: .8rem;
}
.messages { position: relative; overflow-anchor: none; }
.media-tile, .media-video {
  position: relative;
  width: min(240px, 54vw);
  aspect-ratio: 4 / 3;
  padding: 0;
  margin: 5px 0;
  overflow: hidden;
  border-radius: 12px;
  background: var(--soft);
}
.media-tile img { width: 100%; height: 100%; object-fit: cover; }
.media-tile span {
  position: absolute;
  padding: 6px 10px;
  bottom: 7px;
  right: 7px;
  border-radius: 999px;
  background: #1c163cdc;
  color: white;
}
.circle-tile, .circle-preview {
  width: min(170px, 47vw);
  aspect-ratio: 1;
  border-radius: 50%;
  object-fit: cover;
}
.circle-tile span { bottom: auto; right: auto; }
.media-stage { display: grid; place-items: center; margin-top: 12px; }
.media-stage img, .media-stage video { max-width: 100%; max-height: 55dvh; }
#media-progress { width: 100%; accent-color: var(--accent); }
.send-status {
  flex: none;
  min-height: 20px;
  padding: 3px 14px;
  color: var(--muted);
  background: var(--panel);
  font-size: .75rem;
}
.send-status:empty { display: none; }
#attach, #record { min-width: 42px; padding-inline: 8px; }
.call-menu { position: relative; flex: none; }
.call-menu summary {
  display: grid;
  place-items: center;
  list-style: none;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: var(--soft);
  cursor: pointer;
}
.call-menu summary::-webkit-details-marker { display: none; }
.call-menu[open] summary { background: var(--selected); }
.call-options {
  position: absolute;
  top: calc(100% + 7px);
  right: 0;
  z-index: 2;
  display: grid;
  min-width: 157px;
  gap: 4px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 9px 24px var(--shadow);
}
.call-videos { position: relative; }
.call-videos video {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 11px;
  background: #191727;
}
#call-local { position: absolute; width: 28%; bottom: 8px; right: 8px; }
@keyframes message-enter { from { opacity: .6; transform: translateY(4px); } }
@keyframes panel-enter { from { opacity: .6; transform: translateY(6px); } }
@media (prefers-reduced-motion: no-preference) {
  .incoming-message { animation: message-enter .15s ease-out; }
  dialog[open], .call-menu[open] .call-options { animation: panel-enter .16s ease-out; }
}
@media (max-width: 640px) {
  .chatbar { gap: 4px; }
  .chatbar #favorite, #invite, #archive, .call-menu summary { min-width: 36px; width: 36px; }
  .chatbar .icon { width: 17px; height: 17px; }
  .compose { gap: 5px; }
  .compose textarea { resize: none; padding-inline: 9px; }
  #attach, #record { min-width: 37px; }
  @media (prefers-reduced-motion: no-preference) {
    .chat-open .conversation { animation: panel-enter .14s ease-out; }
  }
}

@media (max-width: 640px) { .shell { height: var(--mobile-height, 100dvh); } }
.settings-group { margin-top: 12px; padding: 10px 13px; background: var(--soft); border-radius: 12px; }
.settings-group summary { cursor: pointer; font-weight: 650; }
.settings-group .compact-option { display: flex; align-items: center; }
.compact-option input { width: auto; }
[data-compact] .room { min-height: 46px; margin-bottom: 2px; }
[data-compact] .room .avatar { width: 32px; height: 32px; }
@media (min-width: 821px) {
  .shell { width: 100%; height: 100dvh; border: 0; border-radius: 0; margin: 0; box-shadow: none; }
  .workspace { background-image: radial-gradient(ellipse at 70% 20%,var(--selected),transparent 70%); }
}
