:root {
	--bg: #f2f3f5;
	--panel: #ffffff;
	--text: #14171c;
	--muted: #6b7380;
	--line: #e3e6ea;
	--brand: #1b62c0;
	--brand-text: #ffffff;
	--mine: #d6e8ff;
	--theirs: #ffffff;
	--danger: #c62828;
	--chat-bg: #e9edf2;
	color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
	:root {
		--bg: #0f1216;
		--panel: #171b21;
		--text: #e8ebef;
		--muted: #8b94a1;
		--line: #262c34;
		--brand: #3d86e6;
		--mine: #1d4f8f;
		--theirs: #222831;
		--chat-bg: #0c0f13;
	}
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* no double-tap zoom, like a native app */
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; }
/* same color as the app: any area iOS leaves outside the app (bottom bar, overscroll) blends in */
html { background: var(--panel); }
@media (min-width: 901px) { body { background: var(--bg); } }
html, body { margin: 0; height: 100%; color: var(--text);
	font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; font-size: 16px; color: var(--text); }
/* fixed to the screen edges: 100dvh left an empty band at the bottom of the iOS home-screen app */
#app { position: fixed; inset: 0; display: flex; flex-direction: column; max-width: 900px; margin: 0 auto; background: var(--panel); }
.splash { flex: 1; display: grid; place-items: center; }
.splash img { width: 96px; border-radius: 22px; }

/* top bar */
/* iOS blurs everything just below the status bar: the header text starts lower to stay sharp */
.bar { display: flex; align-items: center; gap: 10px; padding: calc(env(safe-area-inset-top) + 26px) 12px 12px;
	background: var(--brand); color: var(--brand-text); min-height: 56px; flex-shrink: 0; }
.bar h1 { font-size: 19px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .sub { font-size: 12.5px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .title { flex: 1; min-width: 0; }
.bar .title h1 { font-size: 17px; }
.icon-btn { background: none; border: 0; color: inherit; padding: 6px 8px; font-size: 22px; line-height: 1; border-radius: 10px; }
.icon-btn:active { background: rgba(255, 255, 255, .18); }

/* login */
.login { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 24px; gap: 14px;
	padding-top: calc(env(safe-area-inset-top) + 24px); }
.login img { width: 84px; border-radius: 20px; align-self: center; }
.login h1 { text-align: center; margin: 4px 0 8px; font-size: 24px; }
.login p { margin: 0; color: var(--muted); text-align: center; }
.field { width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); }
.field:focus { outline: 2px solid var(--brand); border-color: transparent; }
.primary { padding: 13px; border-radius: 12px; border: 0; background: var(--brand); color: #fff; font-weight: 600; }
.primary:disabled { opacity: .6; }
.link { background: none; border: 0; color: var(--brand); padding: 6px; }
.error { color: var(--danger); text-align: center; min-height: 1.3em; font-size: 14.5px; }
.code { letter-spacing: .5em; text-align: center; font-size: 24px; }

/* conversation list */
.list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border: 0; background: none; width: 100%;
	text-align: left; border-bottom: 1px solid var(--line); }
.row:active { background: var(--bg); }
.row .main { flex: 1; min-width: 0; }
.row .top { display: flex; justify-content: space-between; gap: 8px; }
.row .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .time { color: var(--muted); font-size: 12.5px; flex-shrink: 0; }
.row .preview { color: var(--muted); font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; gap: 8px; justify-content: space-between; }
.row .preview span { overflow: hidden; text-overflow: ellipsis; }
.row.unread .time { color: var(--brand); font-weight: 600; }
.badge { background: var(--brand); color: #fff; border-radius: 999px; font-size: 12px; font-weight: 700; padding: 1px 7px; flex-shrink: 0; }
.avatar { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700;
	flex-shrink: 0; font-size: 17px; }
.avatar.small { width: 36px; height: 36px; font-size: 14px; }
.empty { color: var(--muted); text-align: center; padding: 40px 24px; }
.fab { position: fixed; right: max(18px, calc(50% - 450px + 18px)); bottom: calc(min(env(safe-area-inset-bottom), 22px) + 16px);
	width: 58px; height: 58px; border-radius: 18px; border: 0; background: var(--brand); color: #fff; font-size: 30px;
	box-shadow: 0 4px 14px rgba(0, 0, 0, .25); }
.section { padding: 14px 14px 6px; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.check { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); flex-shrink: 0; display: grid; place-items: center; }
.row.selected .check { background: var(--brand); border-color: var(--brand); color: #fff; }
.form { padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }

/* chat */
.messages { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; background: var(--chat-bg); padding: 10px 10px 6px;
	display: flex; flex-direction: column; gap: 3px; }
.day { align-self: center; background: var(--panel); color: var(--muted); font-size: 12.5px; padding: 3px 10px; border-radius: 8px; margin: 8px 0; }
.msg { max-width: min(78%, 520px); padding: 6px 9px 4px; border-radius: 12px; background: var(--theirs); align-self: flex-start;
	box-shadow: 0 1px 1px rgba(0, 0, 0, .06); position: relative; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.mine { align-self: flex-end; background: var(--mine); }
.msg.first { margin-top: 6px; }
.msg .who { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.msg .text { white-space: pre-wrap; }
.msg .text a { color: var(--brand); }
.msg .meta { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.msg .media { display: grid; gap: 3px; margin: 2px -5px 2px; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.msg .media.single { grid-template-columns: 1fr; }
.msg .media img, .msg .media video { width: 100%; max-height: 340px; object-fit: cover; border-radius: 9px; display: block; background: rgba(0, 0, 0, .08); }
.msg .media.single img, .msg .media.single video { max-width: 300px; object-fit: contain; }
.msg.pending { opacity: .75; }
.progress { height: 4px; background: rgba(0, 0, 0, .1); border-radius: 2px; overflow: hidden; margin-top: 4px; }
.progress div { height: 100%; background: var(--brand); width: 0; transition: width .2s; }
.more { align-self: center; margin: 6px; border: 0; background: var(--panel); color: var(--brand); border-radius: 999px; padding: 5px 14px; font-size: 14px; }

/* the full iOS bottom inset left a thick empty band: keep just enough room for the home indicator */
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 8px max(8px, min(env(safe-area-inset-bottom), 22px));
	background: var(--panel); border-top: 1px solid var(--line); flex-shrink: 0; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); background: var(--bg); border-radius: 20px;
	padding: 9px 14px; max-height: 140px; min-height: 40px; line-height: 1.3; }
.composer textarea:focus { outline: none; border-color: var(--brand); }
.round { width: 40px; height: 40px; border-radius: 50%; border: 0; display: grid; place-items: center; font-size: 20px; flex-shrink: 0; }
.round.send { background: var(--brand); color: #fff; }
.round.attach { background: none; color: var(--muted); font-size: 24px; }
.staged { display: flex; gap: 6px; padding: 6px 8px 0; overflow-x: auto; background: var(--panel); }
.staged .item { position: relative; flex-shrink: 0; }
.staged img, .staged video { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; display: block; }
.staged button { position: absolute; top: -4px; right: -4px; width: 22px; height: 22px; border-radius: 50%; border: 0;
	background: rgba(0, 0, 0, .7); color: #fff; font-size: 12px; padding: 0; }

/* full-screen viewer */
#viewer { position: fixed; inset: 0; background: #000; z-index: 50; display: flex; align-items: center; justify-content: center; }
#viewer[hidden] { display: none; }
#viewer img, #viewer video { max-width: 100%; max-height: 100%; }
#viewer .close { position: absolute; top: calc(env(safe-area-inset-top) + 8px); right: 10px; color: #fff; font-size: 28px; }
#viewer .save { position: absolute; bottom: calc(env(safe-area-inset-bottom) + 14px); left: 50%; transform: translateX(-50%);
	border: 0; border-radius: 999px; padding: 9px 18px; background: rgba(255, 255, 255, .2); color: #fff; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 90px);
	background: rgba(20, 20, 20, .88); color: #fff; padding: 9px 16px; border-radius: 12px; z-index: 60; font-size: 14.5px; max-width: 90%; }
.tick { margin-left: 4px; letter-spacing: -3px; font-size: 12px; }
.tick.read { color: #1e9bf0; font-weight: 700; }
.tick.delivered { font-weight: 700; }
