:root {
  color-scheme: light;
  --paper: #fff;
  --canvas: #f4f7fb;
  --surface: #f8fafc;
  --text: #17253c;
  --muted: #54647c;
  --line: #dce5ef;
  --control: #8294aa;
  --accent: #155cd7;
  --button: #155cd7;
  --button-text: #fff;
  --selected: #e7f0ff;
  --out: #e4efff;
  --ok: #13745b;
  --error: #b72c43;
  --warning: #865210;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #152237;
  --canvas: #0e1828;
  --surface: #19283e;
  --text: #edf4ff;
  --muted: #a7b8cf;
  --line: #2b3e57;
  --control: #7286a1;
  --accent: #8dbaff;
  --button: #80b0ff;
  --button-text: #10213c;
  --selected: #203b60;
  --out: #233e64;
  --ok: #74dbb2;
  --error: #ff9da9;
  --warning: #ffc979;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--canvas); color: var(--text); font: 14px/1.5 system-ui, -apple-system, sans-serif; }
h1, h2, p { margin: 0; }
h1 { font-size: 24px; line-height: 32px; letter-spacing: -.5px; }
h2 { font-size: 16px; line-height: 24px; }
strong, button { font-weight: 650; }
button, input, textarea, select {
  font: inherit;
  color: inherit;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 10px;
  padding: 9px 12px;
}
button { font-weight: 650; }
button, select { cursor: pointer; }
input, textarea, select { border-color: var(--control); min-width: 0; }
input::placeholder, textarea::placeholder { color: var(--muted); }
button:hover:not(:disabled) { background: var(--selected); }
button:disabled { opacity: .55; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
a { color: var(--accent); text-underline-offset: 2px; }
.primary { background: var(--button); color: var(--button-text); border-color: transparent; }
.primary:hover:not(:disabled) { background: var(--button); filter: brightness(.92); }
.icon-button { display: grid; place-items: center; width: 42px; height: 42px; padding: 0; flex: none; font-size: 20px; line-height: 1; }
.muted, small { color: var(--muted); font-size: 12px; line-height: 18px; }
.error { color: var(--error); overflow-wrap: anywhere; }
.error:empty { display: none; }
.ellipsis { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 24px 16px; color: var(--muted); text-align: center; }
.topbar {
  height: 72px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 24px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.brand, .top-actions { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand img { flex: none; object-fit: contain; object-position: center; }
.brand > div { min-width: 0; }
.brand strong { display: block; font-size: 18px; line-height: 24px; letter-spacing: -.35px; }
.brand span { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.top-actions button { white-space: nowrap; }
.reply-label-short { display: none; }
.signin { display: flex; flex-direction: column; min-height: 100dvh; }
.signin-stage { flex: 1; display: grid; place-items: center; padding: 24px; }
.signin-card {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: min(100%, 800px);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 20px 60px #09132316;
}
.signin-art { display: grid; place-items: center; background: radial-gradient(ellipse, var(--out), var(--surface) 76%); }
.signin-art img { display: block; width: min(100%, 375px); height: auto; }
.login-form { display: grid; gap: 16px; align-content: center; padding: 32px; }
.login-form h1 { margin-bottom: 8px; }
.login-form label, #replyForm label { display: grid; gap: 4px; font-weight: 650; }
.login-form .primary { width: 100%; }
.workspace { height: 100dvh; display: flex; flex-direction: column; }
.notice { flex: none; padding: 8px 24px; color: var(--warning); background: var(--surface); border-bottom: 1px solid var(--line); }
.layout { position: relative; flex: 1; min-height: 0; display: grid; grid-template-columns: 320px minmax(0, 1fr) 276px; }
.sidebar { min-height: 0; display: flex; flex-direction: column; background: var(--paper); border-right: 1px solid var(--line); }
.sidebar-tools { padding: 16px 16px 12px; display: grid; gap: 8px; }
.sidebar-tools > label { color: var(--muted); font-size: 12px; }
.select-field { position: relative; min-width: 0; }
.select-field select { appearance: none; display: block; width: 100%; padding-inline-end: 44px; text-overflow: ellipsis; }
.select-field::after {
  content: "";
  position: absolute;
  top: calc(50% - 5px);
  inset-inline-end: 21px;
  width: 7px;
  height: 7px;
  border-inline-end: 2px solid var(--muted);
  border-block-end: 2px solid var(--muted);
  transform: rotate(45deg);
  pointer-events: none;
}
.list-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; }
.list-actions { display: flex; gap: 6px; }
.search-icon { position: relative; width: 13px; height: 13px; border: 2px solid currentColor; border-radius: 50%; margin: 0 3px 3px 0; }
.search-icon::after { content: ""; position: absolute; top: 9px; left: 9px; width: 7px; height: 2px; border-radius: 2px; background: currentColor; transform: rotate(45deg); transform-origin: left center; }
#toggleSearch[aria-expanded="true"] { background: var(--selected); color: var(--accent); }
.filters { display: flex; flex-wrap: wrap; gap: 4px; }
.filters button { padding: 6px 7px; font-size: 12px; }
.filters [aria-pressed="true"], .chat.active { background: var(--selected); color: var(--accent); border-color: transparent; }
.chat-list { overflow: auto; flex: 1; }
.chat-loader { display: grid; place-items: center; height: 36px; }
.chat-loader span { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: chat-spin .8s linear infinite; }
@keyframes chat-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .chat-loader span { animation: none; } }
.chat {
  position: relative;
  width: 100%;
  min-height: 88px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 50px;
  align-items: start;
  gap: 10px;
  padding: 12px 12px 12px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  text-align: left;
}
.chat.active { border-bottom-color: var(--line); }
.chat.active::before {
  content: "";
  position: absolute;
  inset-block: 12px;
  inset-inline-start: 0;
  width: 3px;
  border-radius: 3px;
  background: var(--accent);
}
.chat:focus-visible { outline-offset: -2px; }
.chat-copy, .chat-meta { display: grid; min-width: 0; }
.chat-copy strong { font-size: 15px; line-height: 21px; }
.chat-snippet { color: var(--text); font-size: 14px; line-height: 20px; font-weight: 400; }
.chat.is-unread .chat-snippet { font-weight: 650; }
.chat-meta { justify-items: end; gap: 7px; padding-top: 2px; }
.chat-meta small { font-variant-numeric: tabular-nums; white-space: nowrap; }
.chat-account { color: var(--muted); font-size: 12px; line-height: 18px; font-weight: 400; }
.avatar {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: none;
  background: var(--selected);
  color: var(--accent);
  font-weight: 700;
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: inherit; object-fit: cover; }
.chat .avatar { width: 44px; height: 44px; font-size: 15px; }
.chat:nth-child(3n + 2) .avatar { background: var(--out); }
.chat-indicators { display: flex; align-items: center; gap: 7px; }
.unread-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--button); }
.important-star, #toggleImportant[aria-pressed="true"] { color: var(--warning); }
.important-star { font-size: 15px; line-height: 16px; }
.thread { min-height: 0; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); }
.thread-empty { place-self: center; display: grid; gap: 4px; }
.thread-empty strong { color: var(--text); font-size: 16px; }
.thread-view { height: 100%; min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.thread-head { display: flex; align-items: center; gap: 12px; min-height: 72px; padding: 12px 24px; background: var(--paper); border-bottom: 1px solid var(--line); }
.thread-person { min-width: 0; flex: 1; overflow-wrap: anywhere; }
.back, #showDetails, #closeDetails { display: none; }
.thread-error { background: var(--surface); padding: 8px 24px; }
.timeline { flex: 1; min-height: 0; overflow: auto; overflow-anchor: none; padding: 24px; }
#messages { display: flex; flex-direction: column; gap: 12px; }
.message-date { padding: 4px 0; text-align: center; font-size: 12px; color: var(--muted); }
.bubble {
  max-width: min(75%, 520px);
  align-self: flex-start;
  padding: 10px 13px;
  border-radius: 15px 15px 15px 5px;
  border: 1px solid var(--line);
  background: var(--paper);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.bubble.out { align-self: flex-end; background: var(--out); border-color: transparent; border-radius: 15px 15px 5px 15px; }
.bubble.system { align-self: center; background: transparent; color: var(--muted); font-size: 12px; }
.bubble time { display: block; margin-top: 4px; text-align: right; color: var(--muted); font-size: 11px; }
.bubble .origin { color: var(--accent); font-size: 12px; font-weight: 650; margin-bottom: 4px; }
.bubble img { display: block; width: auto; max-width: 100%; max-height: 230px; object-fit: contain; border-radius: 8px; cursor: zoom-in; }
.more { display: block; margin: 6px auto 12px; }
.composer { padding: 12px 24px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; background: var(--paper); border-top: 1px solid var(--line); }
.composer textarea { width: 100%; min-height: 58px; resize: vertical; max-height: 160px; }
.compose-tools, .attachment { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.compose-tools #sendText { margin-inline-start: auto; }
.attachment { background: var(--surface); border-radius: 10px; padding: 6px 8px; }
.attachment img { width: 42px; height: 34px; object-fit: cover; border-radius: 5px; }
.attachment span { min-width: 0; overflow-wrap: anywhere; margin-inline-end: auto; }
.context { min-height: 0; overflow: auto; border-left: 1px solid var(--line); background: var(--paper); padding: 24px 20px; }
.context-head, .dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.listing-card { display: grid; gap: 6px; padding: 14px; margin: 12px 0 22px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow-wrap: anywhere; }
.listing-card img { width: 100%; height: auto; max-height: 150px; object-fit: cover; border-radius: 8px; margin-bottom: 4px; }
.listing-card span { color: var(--muted); }
.context dl { display: grid; gap: 12px; margin: 12px 0; }
.context dt { color: var(--muted); font-size: 12px; }
.context dd { margin: 0; overflow-wrap: anywhere; }
dialog {
  width: min(520px, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  overflow: auto;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--paper);
  color: var(--text);
}
dialog::backdrop { background: #081323a3; }
.dialog-head { margin-bottom: 12px; }
.reply-list { display: grid; gap: 8px; margin: 12px 0; max-height: 28vh; overflow: auto; }
.reply { border: 1px solid var(--line); background: var(--surface); padding: 12px; border-radius: 10px; overflow-wrap: anywhere; }
.reply p { white-space: pre-wrap; margin: 4px 0 8px; }
.reply button + button { margin-inline-start: 8px; }
#replyForm { display: grid; gap: 8px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; }
#photoDialog { width: fit-content; max-width: calc(100vw - 24px); }
#fullPhoto { display: block; width: auto; height: auto; max-width: 100%; max-height: 72dvh; object-fit: contain; margin: 0 auto 12px; }

@media (max-width: 1050px) {
  .layout { grid-template-columns: 290px minmax(0, 1fr); }
  .context { display: none; }
  .context.open { display: block; position: absolute; z-index: 2; top: 72px; right: 0; bottom: 0; width: min(276px, 100%); box-shadow: -8px 0 28px #09132322; }
  #showDetails, #closeDetails { display: grid; place-items: center; }
}
@media (max-width: 640px) {
  body:has(.workspace:not([hidden])) { overflow: hidden; }
  .workspace { height: var(--mobile-viewport-height, 100dvh); overflow: hidden; }
  .topbar { height: 60px; padding: 0 12px; gap: 6px; }
  .brand { gap: 6px; }
  .brand img { width: 34px; height: 34px; }
  .brand span { display: none; }
  .top-actions { gap: 4px; }
  .top-actions button { padding: 6px; font-size: 12px; }
  button, select, input { min-height: 44px; }
  input, textarea, select { font-size: 16px; }
  .icon-button { width: 44px; height: 44px; }
  .theme-toggle { font-size: 18px !important; }
  .layout { display: block; }
  .sidebar, .thread { height: 100%; border: 0; }
  .thread, .layout.open .sidebar { display: none; }
  .layout.open .thread { display: grid; }
  .back { display: grid; }
  .thread-head, .timeline, .composer { padding-left: 12px; padding-right: 12px; }
  .thread-head { gap: 8px; }
  .thread-head, .composer { flex: none; }
  .thread-head .avatar { width: 34px; height: 34px; }
  .bubble { max-width: 88%; }
  .notice { padding-inline: 12px; }
  .signin-stage { padding: 12px; }
  .signin-card { grid-template-columns: minmax(0, 1fr); max-width: 400px; }
  .signin-art img { width: min(100%, 200px); }
  .login-form { padding: 24px; }
  .compose-tools { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; }
  .compose-tools #sendText { margin: 0; }
  .compose-tools .select-field select { padding-inline: 8px 27px; }
  .compose-tools .select-field::after { inset-inline-end: 12px; }
}
@media (max-width: 360px) {
  .topbar { padding-inline: 8px; }
  .brand strong { font-size: 15px; }
  .reply-label { display: none; }
  .reply-label-short { display: inline; }
  .compose-tools { gap: 6px; }
  .compose-tools button { font-size: 12px; padding-inline: 8px; }
}
