:root {
  color-scheme: light;
  --surface: #fff;
  --ink: #202124;
  --muted: #5c6269;
  --line: #e0e2e5;
  --accent: #176fae;
  --chat: #f1f2f4;
  --pattern: #b5b8bf55;
  --mine: #e4edf6;
  --chip: #e9edf2;
  --error: #723c2e;
  --glass: #ffffffc9;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface: #222427;
  --ink: #f0f1f2;
  --muted: #b9bec5;
  --line: #3b3e43;
  --accent: #78c4ff;
  --chat: #17181b;
  --pattern: #a6a9ae29;
  --mine: #273e53;
  --chip: #32363c;
  --error: #e1b5a0;
  --glass: #222427cc;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; color: var(--ink); background: var(--chat); }
a { color: inherit; }
button, textarea { font: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.shell {
  width: min(100%, 720px);
  height: 100vh;
  height: 100dvh;
  margin: auto;
  display: flex;
  flex-direction: column;
  background: radial-gradient(circle, var(--pattern) 1px, transparent 1.6px) 0 0 / 22px 22px, var(--chat);
  box-shadow: 0 0 60px #16395422;
}
.masthead {
  background: var(--glass);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: max(11px, env(safe-area-inset-top)) 16px 11px;
}
.identity { min-width: 0; display: flex; align-items: center; gap: 10px; }
.identity > div { min-width: 0; }
.monogram {
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 50%;
  background: linear-gradient(155deg, #4b9ede, #286fad);
  color: #fff;
  font-size: 19px;
  font-weight: 650;
}
.monogram img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
h1 { margin: 0; font-size: 17px; line-height: 1.25; overflow-wrap: anywhere; }
#profile { color: var(--accent); font-size: 13px; text-decoration: none; }
nav { display: flex; gap: 6px; }
nav a, .open-bot {
  background: var(--chip);
  color: var(--accent);
  padding: 8px 10px;
  border-radius: 16px;
  text-decoration: none;
  font-size: 12px;
  font-weight: 650;
}
.intro {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 24px;
}
.intro h2, .intro p { width: min(100%, 320px); background: var(--surface); margin: 0; }
.intro h2 { border-radius: 16px 16px 0 0; padding: 14px 15px 5px; font-size: 16px; }
.intro p { border-radius: 0 0 16px 5px; padding: 0 15px 14px; font-size: 15px; line-height: 1.45; }
.open-bot { margin-top: 14px; }
.thread, .inbox { flex: 1; min-height: 0; overflow: auto; padding: 14px clamp(12px, 4vw, 24px); }
.inbox { background: var(--surface); padding-block: 0; }
.messages { display: grid; align-content: end; min-height: 100%; gap: 7px; }
.day {
  justify-self: center;
  margin: 7px 0;
  padding: 4px 10px;
  background: var(--glass);
  color: var(--muted);
  border-radius: 16px;
  font-size: 12px;
  font-weight: 600;
}
.message {
  max-width: 86%;
  width: fit-content;
  border-radius: 14px 14px 14px 5px;
  padding: 8px 11px 6px;
  background: var(--surface);
  box-shadow: 0 1px 2px #14385414;
}
.message.mine { justify-self: end; background: var(--mine); border-radius: 14px 14px 5px 14px; }
.message p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.4; }
.message time { display: block; text-align: right; color: var(--muted); font-size: 11px; margin-top: 3px; }
.back, .older { color: var(--accent); border: 0; }
.back { background: transparent; font-size: 30px; line-height: 1; min-width: 32px; min-height: 40px; }
.older { background: var(--surface); border-radius: 20px; display: block; margin: 0 auto 12px; font-size: 13px; padding: 8px 12px; }
.contact {
  text-align: left;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  background: transparent;
  padding: 12px 5px;
}
.contact:hover { background: var(--chip); }
.contact-details { display: grid; gap: 4px; }
.contact-details > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-details > span, .contact time { color: var(--muted); font-size: 13px; }
.contact time { align-self: start; padding-top: 3px; font-size: 11px; }
.empty-inbox { text-align: center; color: var(--muted); margin: 28px 0; }
footer { flex: 0 0 auto; background: var(--surface); }
footer:has(.composer[hidden]):has(#status:empty) { display: none; }
#status { margin: 0; color: var(--error); font-size: 13px; text-align: center; }
#status:not(:empty) { padding: 7px 12px; }
.composer {
  display: flex;
  align-items: end;
  gap: 9px;
  border-top: 1px solid var(--line);
  padding: 7px 12px max(7px, env(safe-area-inset-bottom));
}
textarea {
  flex: 1;
  min-width: 0;
  border: 0;
  background: var(--chip);
  color: var(--ink);
  padding: 10px 13px;
  font-size: 16px;
  line-height: 20px;
  resize: none;
  field-sizing: content;
  max-height: 110px;
  border-radius: 20px;
}
textarea::placeholder { color: var(--muted); }
#send { width: 40px; height: 40px; border: 0; border-radius: 50%; color: white; background: #1979ba; font-size: 20px; }
#send span { display: inline-block; transform: rotate(-24deg); }
#send:disabled { opacity: .5; cursor: default; }
@media (max-width: 350px) {
  .masthead { padding-inline: 10px; }
  nav a { padding-inline: 7px; }
}

.peer-handle { display: block; color: var(--muted); font-size: 13px; }
.peer-profile {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 7px 12px;
  background: var(--glass);
  color: var(--accent);
  font-size: 13px;
  font-weight: 650;
}
.peer-profile:disabled { opacity: .6; cursor: default; }
.message:not(.mine) { background: var(--glass); }
