/* Foresight chat app. Mobile-first; light/dark follow the phone's setting. */
:root {
	--brand: #1f3a8a;
	--brand-2: #2f56c5;
	--bg: #f2f4f8;
	--surface: #ffffff;
	--text: #14171f;
	--muted: #687082;
	--line: #e3e6ee;
	--mine: #2f56c5;
	--mine-text: #ffffff;
	--theirs: #ffffff;
	--danger: #c0392b;
	--danger-bg: #fdecea;
	--shadow: 0 1px 2px rgba(20, 23, 31, .08);
	--safe-top: env(safe-area-inset-top, 0px);
	--safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
	:root {
		--bg: #0f1218;
		--surface: #1a1f29;
		--text: #e9ecf2;
		--muted: #949bab;
		--line: #2a303c;
		--mine: #3a63d8;
		--theirs: #232937;
		--danger-bg: #3a1d1a;
		--shadow: none;
	}
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
	font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	background: var(--bg); color: var(--text);
	-webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent;
	overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

/* ---------- Login ---------- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100%; padding: calc(24px + var(--safe-top)) 16px calc(24px + var(--safe-bottom)); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 18px; padding: 28px 22px; box-shadow: 0 4px 24px rgba(20, 23, 31, .08); text-align: center; }
.login-logo { border-radius: 18px; }
.login-card h1 { margin: 12px 0 4px; font-size: 26px; }
.login-card form { text-align: left; margin-top: 18px; }
.login-card label, .sheet label { display: block; font-weight: 600; font-size: 14px; margin: 14px 0 6px; }
.login-card input, .sheet select {
	width: 100%; font-size: 18px; padding: 13px 14px; border-radius: 12px;
	border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.login-card input:focus, .sheet select:focus, .composer textarea:focus { outline: 2px solid var(--brand-2); outline-offset: 0; border-color: transparent; }
.pin-input { letter-spacing: 12px; text-align: center; font-size: 24px !important; }
.btn-primary, .btn-secondary {
	display: block; width: 100%; margin-top: 22px; padding: 14px; border: 0; border-radius: 12px;
	background: var(--brand); color: #fff; font-weight: 600; font-size: 17px;
}
.btn-secondary { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn-link { display: block; width: 100%; margin-top: 10px; padding: 12px; border: 0; background: none; color: var(--brand-2); font-weight: 600; }
.btn-small { border: 0; border-radius: 999px; padding: 7px 14px; background: var(--brand); color: #fff; font-weight: 600; font-size: 14px; white-space: nowrap; }
.btn-small.off { background: var(--line); color: var(--text); }
.alert { background: var(--danger-bg); color: var(--danger); border-radius: 10px; padding: 10px 12px; margin-top: 14px; font-size: 15px; }

/* Human check on the login page */
.human-check { margin-top: 18px; min-height: 65px; }
.captcha-box { display: flex; gap: 8px; align-items: center; }
.captcha-box img { flex: 1; min-width: 0; width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--line); background: #eef2fa; }
.captcha-new { flex: none; width: 48px; height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 22px; }
.captcha-input { margin-top: 8px; text-transform: uppercase; letter-spacing: 6px; text-align: center; font-weight: 700; }

.remember-row { display: flex !important; align-items: center; gap: 10px; font-weight: 500 !important; margin: 18px 0 0 !important; cursor: pointer; }
.remember-row input { width: 22px !important; height: 22px; flex: none; accent-color: var(--brand-2); }

.btn-bio { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 18px; }
.btn-bio:disabled { opacity: .6; }
.bio-note { text-align: center; margin: 6px 0 0; }
.or-line { display: flex; align-items: center; gap: 10px; margin: 18px 0 0; color: var(--muted); font-size: 13px; }
.or-line::before, .or-line::after { content: ''; flex: 1; height: 1px; background: var(--line); }

/* ---------- App frame ---------- */
#app { height: 100%; }
.view { display: flex; flex-direction: column; height: 100%; height: var(--app-h, 100dvh); }
.bar {
	display: flex; align-items: center; gap: 4px; flex: none;
	padding: calc(8px + var(--safe-top)) 8px 8px 16px;
	background: var(--brand); color: #fff;
}
.bar h1 { flex: 1; margin: 0; font-size: 21px; }
.icon-btn { flex: none; display: grid; place-items: center; width: 42px; height: 42px; border: 0; border-radius: 50%; background: transparent; color: #fff; }
.icon-btn:active { background: rgba(255, 255, 255, .15); }
.icon-btn.on { background: rgba(255, 255, 255, .22); }
#roomView .bar { padding-left: 4px; }
.room-title { flex: 1; min-width: 0; border: 0; background: none; color: #fff; text-align: left; padding: 2px 4px; }
.room-title span { display: block; font-weight: 700; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-title small { display: block; opacity: .8; font-size: 12px; }

.banner { margin: 10px 12px 0; padding: 12px 14px; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); font-size: 14px; display: flex; gap: 10px; align-items: center; }
.banner span { flex: 1; }

/* ---------- Room list ---------- */
.room-list { list-style: none; margin: 0; padding: 6px 0 calc(12px + var(--safe-bottom)); overflow-y: auto; flex: 1; }
.room-list li { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.room-list li:active { background: var(--bg); }
.room-avatar { flex: none; width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 19px; }
.room-main { flex: 1; min-width: 0; }
.room-top { display: flex; justify-content: space-between; gap: 8px; }
.room-top strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-top time { flex: none; font-size: 12px; color: var(--muted); }
.room-last { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 14px; }
.room-last span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread { flex: none; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--brand-2); color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.empty { padding: 40px 24px; text-align: center; color: var(--muted); }

/* ---------- Messages ---------- */
.messages { flex: 1; overflow-y: auto; padding: 10px 10px 6px; -webkit-overflow-scrolling: touch; }
.load-older { display: block; margin: 4px auto 10px; border: 0; border-radius: 999px; padding: 7px 14px; background: var(--surface); color: var(--brand-2); font-size: 14px; box-shadow: var(--shadow); }
.day { text-align: center; margin: 14px 0 8px; }
.day span { display: inline-block; font-size: 12px; color: var(--muted); background: var(--surface); padding: 3px 10px; border-radius: 999px; box-shadow: var(--shadow); }
.msg { display: flex; gap: 8px; margin: 2px 0; align-items: flex-end; }
.msg.mine { justify-content: flex-end; }
.msg .av { flex: none; width: 30px; height: 30px; border-radius: 50%; color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.msg .av.ghost { visibility: hidden; }
.bubble { max-width: min(78%, 560px); padding: 7px 11px 6px; border-radius: 16px; background: var(--theirs); box-shadow: var(--shadow); overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.mine .bubble { background: var(--mine); color: var(--mine-text); }
.msg.first .bubble { margin-top: 6px; }
.bubble .who { display: block; font-size: 13px; font-weight: 700; margin-bottom: 1px; }
.bubble .meta { display: block; text-align: right; font-size: 11px; opacity: .65; margin-top: 2px; }
.bubble a { color: inherit; text-decoration: underline; }
.bubble .tr-note { display: block; font-size: 11px; font-style: italic; opacity: .7; margin-top: 3px; }
.msg.pending .bubble { opacity: .6; }
.msg.failed .bubble { outline: 2px solid var(--danger); }

/* ---------- Logged-in devices ---------- */
.row-btn { display: flex; width: 100%; align-items: center; gap: 8px; margin: 14px 0 4px; padding: 0; border: 0; background: none; text-align: left; font-weight: 600; }
.row-btn span:first-child { flex: 1; }
.device-list { list-style: none; margin: 8px 0 0; padding: 0; }
.device { display: flex; gap: 10px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.device-icon { flex: none; width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--bg); color: var(--brand-2); }
.device.current .device-icon { background: var(--brand-2); color: #fff; }
.device-main { flex: 1; min-width: 0; font-size: 14px; }
.device-line { font-size: 13px; margin-top: 2px; overflow-wrap: anywhere; }
.this-device { display: inline-block; font-size: 11px; font-weight: 700; color: #1e9e5a; border: 1px solid #1e9e5a; border-radius: 999px; padding: 0 6px; margin-left: 4px; }
.device-out { flex: none; align-self: center; }
#logoutOthersBtn { margin-top: 16px; }
#logoutAllBtn { margin-top: 10px; }

/* ---------- Offline ---------- */
.offline-bar { flex: none; padding: 7px 12px; background: #8a5a00; color: #fff; font-size: 13px; text-align: center; }

/* ---------- Composer ---------- */
.composer { flex: none; display: flex; gap: 8px; align-items: flex-end; padding: 8px 10px calc(8px + var(--safe-bottom)); background: var(--surface); border-top: 1px solid var(--line); }
.composer textarea {
	flex: 1; resize: none; max-height: 140px; font: inherit; font-size: 16px; line-height: 1.35;
	padding: 10px 14px; border-radius: 20px; border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.send-btn { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--brand-2); color: #fff; display: grid; place-items: center; }
.send-btn:disabled { opacity: .45; }

/* ---------- Sheets ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 10; }
.sheet {
	position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; max-height: 85dvh; overflow-y: auto;
	background: var(--surface); border-radius: 18px 18px 0 0; padding: 18px 18px calc(14px + var(--safe-bottom));
	max-width: 560px; margin: 0 auto; box-shadow: 0 -4px 24px rgba(0, 0, 0, .15);
}
.sheet h2 { margin: 0 0 10px; font-size: 19px; }
.sheet .who { margin: 0 0 6px; }
.switch-row { display: flex !important; align-items: center; justify-content: space-between; gap: 12px; font-weight: 500 !important; margin: 16px 0 4px !important; }
.switch-row input { width: 22px; height: 22px; flex: none; accent-color: var(--brand-2); }
.setting-block { border-top: 1px solid var(--line); margin-top: 12px; }
.member-list { list-style: none; margin: 0; padding: 0; }
.member-list li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }

.toast { position: fixed; left: 50%; bottom: calc(80px + var(--safe-bottom)); transform: translateX(-50%); background: #222; color: #fff; padding: 9px 16px; border-radius: 999px; font-size: 14px; z-index: 20; max-width: 90%; text-align: center; }

@media (min-width: 700px) {
	#app { max-width: 760px; margin: 0 auto; box-shadow: 0 0 0 1px var(--line); }
}

/* ---------- Presence ---------- */
.member-name { flex: 1; min-width: 0; }
.presence { flex: none; font-size: 12px; color: var(--muted); }
.presence.on { color: #1e9e5a; font-weight: 600; }
.av-dot { position: relative; }
.av-dot.is-on::after { content: ''; position: absolute; right: -1px; bottom: -1px; width: 11px; height: 11px; border-radius: 50%; background: #22c55e; border: 2px solid var(--surface); }

/* ---------- Location under a message ---------- */
.loc-pin { display: inline-flex; align-items: center; gap: 2px; margin-left: 6px; font-size: 11px; font-weight: 500; color: inherit; opacity: .75; text-decoration: none !important; white-space: nowrap; }
.loc-pin svg { flex: none; }
.loc-pin:active { opacity: 1; }
.bubble .who .loc-pin { color: var(--muted); opacity: 1; }
.bubble .meta .loc-pin { margin: 0 6px 0 0; }

/* ---------- Notification prompt ---------- */
.notify-sheet { text-align: center; }
.notify-icon { width: 64px; height: 64px; margin: 4px auto 10px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; }
.install-steps { text-align: left; padding-left: 22px; margin: 10px 0 0; }
.install-steps li { margin: 8px 0; }
