/* Messages-style look: blue sent bubbles, gray received, plain white / true
   black surfaces, gray monogram avatars. */
:root {
	--bg: #ffffff;
	--side: #f5f5f7;
	--fill: #e9e9eb;          /* received bubbles, inputs */
	--fill-2: #dcdce0;
	--line: #e3e3e6;
	--fg: #1d1d1f;
	--muted: #8a8a8e;
	--accent: #007aff;
	--accent-fg: #ffffff;
	--sel: #007aff;           /* selected chat row */
	--sel-fg: #ffffff;
	--danger: #ff3b30;
	--ok: #34c759;
	--mono-1: #a5a8b1;        /* monogram gradient */
	--mono-2: #868994;
	color-scheme: light;
}
@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		--bg: #000000; --side: #121214; --fill: #262629; --fill-2: #323236; --line: #2c2c2e; --fg: #f5f5f7; --muted: #8e8e93;
		--accent: #0a84ff; --sel: #0a84ff; --mono-1: #6e717a; --mono-2: #4f525a; color-scheme: dark;
	}
}
:root[data-theme="dark"] {
	--bg: #000000; --side: #121214; --fill: #262629; --fill-2: #323236; --line: #2c2c2e; --fg: #f5f5f7; --muted: #8e8e93;
	--accent: #0a84ff; --sel: #0a84ff; --mono-1: #6e717a; --mono-2: #4f525a; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
#app { height: 100%; }
h1 { font-size: 26px; font-weight: 700; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 19px; font-weight: 600; margin: 0; }
h3 { font-size: 13px; margin: 18px 0 6px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
p { margin: 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pad { padding: 14px 16px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.noscript { padding: 24px; text-align: center; }
.ico { width: 20px; height: 20px; display: block; }

button, input, textarea, select { font: inherit; color: inherit; }
input, textarea, select { width: 100%; padding: 10px 12px; border: 1px solid transparent; border-radius: 10px; background: var(--fill); outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--muted); }
textarea { resize: none; }
button { cursor: pointer; padding: 9px 16px; border-radius: 10px; border: 0; background: var(--fill); }
button:hover { background: var(--fill-2); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-fg); font-weight: 600; }
button.primary:hover { filter: brightness(1.1); background: var(--accent); }
button.danger { color: var(--danger); }
button.link { background: none; color: var(--accent); padding: 4px 0; }
button.icon { width: 36px; height: 36px; padding: 0; display: grid; place-items: center; background: none; color: var(--accent); border-radius: 50%; flex: none; }
button.icon:hover { background: var(--fill); }

/* ---- forms / cards */
.center { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.card { width: 100%; max-width: 380px; display: grid; gap: 14px; }
.card.wide { max-width: 500px; }
.card h1 { text-align: center; margin-bottom: 6px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field small { color: var(--muted); font-size: 12px; }
fieldset { border: 0; border-radius: 14px; padding: 14px; margin: 0; display: grid; gap: 8px; background: var(--side); }
legend { float: left; font-weight: 600; padding: 0; margin-bottom: 2px; }
fieldset .muted { font-size: 13px; clear: both; }
fieldset input { background: var(--bg); }
.check { display: flex; gap: 10px; align-items: flex-start; }
.check input { width: auto; margin-top: 3px; accent-color: var(--accent); }
.row { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.row.spread { justify-content: space-between; margin-top: 18px; }
.row input { flex: 1; }
.steps { display: flex; gap: 6px; list-style: none; margin: 0 0 4px; padding: 0; font-size: 12px; color: var(--muted); }
.steps li { flex: 1; border-top: 3px solid var(--fill); padding-top: 5px; }
.steps li.on { border-color: var(--accent); color: var(--fg); font-weight: 600; }
.steps li.done { border-color: color-mix(in srgb, var(--accent) 40%, var(--fill)); }
.code { font: 600 19px/1.4 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .06em; text-align: center; padding: 16px; border-radius: 14px; background: var(--side); user-select: all; word-break: break-all; }

.profile-editor { display: grid; gap: 12px; }
.pfp-row { display: flex; gap: 14px; align-items: center; }
.pfp-row > div:last-of-type { display: grid; gap: 4px; justify-items: start; }
.pfp-row small { font-size: 12px; }

/* ---- avatars: photo, or a gray monogram like Contacts */
.avatar { width: 40px; height: 40px; border-radius: 50%; flex: none; object-fit: cover; }
.avatar.xs { width: 28px; height: 28px; font-size: 12px; }
.avatar.sm { width: 32px; height: 32px; font-size: 14px; }
.avatar.md { width: 46px; height: 46px; font-size: 19px; }
.avatar.lg { width: 84px; height: 84px; font-size: 34px; }
.avatar.xl { width: 96px; height: 96px; font-size: 40px; }
.avatar.initials { display: grid; place-items: center; font-weight: 600; color: #fff; background: linear-gradient(180deg, var(--mono-1), var(--mono-2)); }
.avatar-space { width: 28px; flex: none; }
button.avatar-btn { padding: 0; background: none; border-radius: 50%; flex: none; }

/* ---- app shell */
.shell { height: 100%; display: grid; grid-template-columns: 320px 1fr; }
.sidebar { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.sidebar > header { display: flex; align-items: center; gap: 4px; padding: 12px 12px 6px; }
.sidebar > header h1 { flex: 1; font-size: 22px; padding-left: 6px; }
button.me { padding: 0; background: none; border-radius: 50%; }
.filter { display: flex; align-items: center; gap: 6px; margin: 4px 12px 8px; padding: 0 10px; border-radius: 10px; background: var(--fill); color: var(--muted); }
.filter .ico { width: 16px; height: 16px; }
.filter input { background: none; padding: 8px 0; border: 0; }
.room-list { list-style: none; margin: 0; padding: 0 8px 8px; overflow-y: auto; flex: 1; }
button.room { width: 100%; display: flex; gap: 11px; align-items: center; background: none; padding: 9px 10px; text-align: left; border-radius: 12px; }
button.room:hover { background: var(--fill); }
button.room.active { background: var(--sel); color: var(--sel-fg); }
button.room.active .muted, button.room.active time, button.room.active .preview { color: color-mix(in srgb, var(--sel-fg) 80%, transparent); }
.room-text { flex: 1; min-width: 0; display: grid; gap: 1px; }
.room-top, .room-bottom { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.room-top .title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-top time { font-size: 13px; color: var(--muted); flex: none; }
.room-bottom .preview { flex: 1; font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
button.room.unread .preview { color: var(--fg); }
.badge { background: var(--accent); color: var(--accent-fg); border-radius: 999px; font-size: 12px; font-weight: 700; padding: 0 7px; line-height: 20px; flex: none; }
button.room.active .badge { background: var(--sel-fg); color: var(--sel); }

.chat-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg); }
.empty { margin: auto; text-align: center; display: grid; gap: 4px; padding: 24px; color: var(--muted); }
.room-header { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line);
	background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(20px); }
.room-header .back { display: none; }
button.room-title { flex: 1; display: flex; align-items: center; justify-content: center; gap: 10px; background: none; padding: 4px 8px; min-width: 0; border-radius: 12px; }
.room-title-text { display: grid; text-align: left; min-width: 0; }
.room-title-text b, .room-title-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-title-text small { font-size: 12px; }

/* ---- messages */
.messages { list-style: none; margin: 0; padding: 14px 16px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; }
.messages > .day { align-self: center; font-size: 12px; font-weight: 600; color: var(--muted); padding: 14px 0 8px; }
.messages > .older { align-self: center; padding-bottom: 6px; }
.messages > .empty { margin: auto; }
.msg { display: flex; gap: 8px; align-items: flex-end; max-width: min(75%, 560px); margin-top: 2px; }
.msg.first, .msg.single { margin-top: 10px; }
.msg.mine { align-self: flex-end; }
.msg-body { display: grid; gap: 2px; min-width: 0; }
.msg.mine .msg-body { justify-items: end; }
button.sender { background: none; padding: 0 12px; font-size: 12px; color: var(--muted); justify-self: start; border-radius: 6px; }
button.sender:hover { text-decoration: underline; background: none; }
.bubble { background: var(--fill); padding: 8px 13px; border-radius: 19px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.35; }
.msg.mine .bubble { background: var(--accent); color: var(--accent-fg); }
/* joined corners within a group */
.msg.theirs.first .bubble { border-bottom-left-radius: 6px; }
.msg.theirs.middle .bubble { border-top-left-radius: 6px; border-bottom-left-radius: 6px; }
.msg.theirs.last .bubble { border-top-left-radius: 6px; }
.msg.mine.first .bubble { border-bottom-right-radius: 6px; }
.msg.mine.middle .bubble { border-top-right-radius: 6px; border-bottom-right-radius: 6px; }
.msg.mine.last .bubble { border-top-right-radius: 6px; }
.bubble.broken { font-style: italic; color: var(--muted); background: none; border: 1px dashed var(--line); }
.msg time { font-size: 11px; color: var(--muted); padding: 1px 6px 0; }

.composer { display: flex; gap: 8px; padding: 8px 12px 12px; align-items: flex-end; background: var(--bg); }
.composer textarea { max-height: 160px; border-radius: 20px; padding: 9px 16px; background: var(--bg); border: 1px solid var(--line); }
.composer textarea:focus { border-color: var(--fill-2); }
button.send { width: 36px; height: 36px; padding: 0; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--accent-fg); flex: none; margin-bottom: 1px; }
button.send:hover { background: var(--accent); filter: brightness(1.1); }
button.send:disabled { background: var(--fill-2); color: var(--muted); opacity: 1; }

/* ---- dialogs */
.dialog { width: min(440px, calc(100vw - 32px)); max-height: calc(100vh - 48px); border: 0; border-radius: 18px; background: var(--bg); color: var(--fg); padding: 18px;
	box-shadow: 0 20px 60px rgb(0 0 0 / .3); }
.dialog::backdrop { background: rgb(0 0 0 / .35); backdrop-filter: blur(2px); }
.dialog > header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; min-height: 36px; }
.dialog form { display: grid; gap: 12px; }
.sheet { width: min(360px, calc(100vw - 32px)); padding: 8px; display: grid; gap: 2px; }
.sheet[open] { display: grid; }
.sheet button { background: none; padding: 13px; border-radius: 12px; font-size: 16px; color: var(--accent); }
.sheet button:hover { background: var(--fill); }
.sheet button.danger { color: var(--danger); }
.sheet button.cancel { font-weight: 600; margin-top: 4px; border-top: 1px solid var(--line); border-radius: 0 0 12px 12px; }
.sheet-title { text-align: center; font-size: 13px; padding: 8px 8px 6px; }
.user-search { display: grid; gap: 6px; }
.user-results, .member-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
button.user { width: 100%; display: flex; align-items: center; gap: 10px; text-align: left; background: none; padding: 7px 8px; border-radius: 10px; }
button.user:hover { background: var(--fill); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chip { display: inline-flex; align-items: center; gap: 2px; background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); border-radius: 999px; padding: 3px 4px 3px 11px; font-size: 13px; font-weight: 600; }
.chip button { background: none; padding: 0 6px; color: inherit; }
.profile-card { display: grid; justify-items: center; gap: 6px; text-align: center; padding: 0 0 8px; }
.profile-card h2 { margin-top: 6px; }
.profile-card .bio { margin: 6px 0 4px; white-space: pre-wrap; max-width: 34ch; }
.profile-card button.primary { margin-top: 10px; min-width: 160px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100; max-width: calc(100vw - 32px);
	padding: 11px 18px; border-radius: 14px; background: color-mix(in srgb, var(--fg) 92%, transparent); color: var(--bg); box-shadow: 0 8px 30px rgb(0 0 0 / .25); font-size: 14px; }
.toast.error { background: var(--danger); color: #fff; }
.toast.ok { background: color-mix(in srgb, var(--fg) 92%, transparent); color: var(--bg); }

/* ---- phones */
@media (max-width: 720px) {
	.shell { grid-template-columns: 1fr; }
	.shell .chat-pane { display: none; }
	.shell.in-room .sidebar { display: none; }
	.shell.in-room .chat-pane { display: flex; }
	.room-header .back { display: grid; }
	.msg { max-width: 82%; }
}
