:root {
  --bg: #f2f4f7; --panel: #fff; --text: #111827; --muted: #6b7280; --line: #e5e7eb;
  --brand: #0b5cab; --mine: #d9ebff; --theirs: #fff; --ok: #16a34a; --warn: #dc2626;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1220; --panel: #111a2b; --text: #e5e7eb; --muted: #94a3b8; --line: #1f2a3d;
    --mine: #123a66; --theirs: #172238; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
button, input, textarea { font: inherit; color: inherit; }
.view { display: flex; flex-direction: column; height: 100dvh; padding-top: env(safe-area-inset-top); }
.view[hidden] { display: none; }

header { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--brand); color: #fff; }
header h1 { font-size: 20px; margin: 0; flex: 1; }
.icon { background: none; border: 0; color: inherit; font-size: 22px; min-width: 44px; min-height: 44px; cursor: pointer; }
.state { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: rgba(255,255,255,.2); }
.state.open { background: var(--ok); } .state.bad { background: var(--warn); }

#search { margin: 8px 12px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); }
#chats { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#chats li { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--panel); cursor: pointer; }
.avatar { width: 46px; height: 46px; border-radius: 50%; background: var(--line); flex: none; object-fit: cover;
  display: grid; place-items: center; font-weight: 600; color: var(--muted); }
.meta { flex: 1; min-width: 0; }
.meta .top { display: flex; justify-content: space-between; gap: 8px; }
.meta .top small { color: var(--muted); flex: none; }
.meta .last { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--ok); color: #fff; border-radius: 99px; font-size: 12px; padding: 1px 7px; }

.who { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.who small { opacity: .8; }
#messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 82%; padding: 7px 10px; border-radius: 12px; background: var(--theirs); align-self: flex-start;
  white-space: pre-wrap; word-wrap: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.msg.me { background: var(--mine); align-self: flex-end; }
.msg small { display: block; text-align: right; color: var(--muted); font-size: 11px; }
.msg img, .msg video { max-width: 100%; border-radius: 8px; display: block; }
.msg audio { width: 240px; max-width: 100%; }
.day { align-self: center; font-size: 12px; color: var(--muted); padding: 4px 0; }

#composer { display: flex; align-items: flex-end; gap: 4px; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line); }
#text { flex: 1; resize: none; max-height: 140px; padding: 10px 12px; border-radius: 20px; border: 1px solid var(--line); background: var(--bg); }
.send { color: var(--brand); }
.attach { display: grid; place-items: center; }

#login { align-items: center; justify-content: center; gap: 12px; padding: 24px; }
.logo { width: 88px; height: 88px; border-radius: 20px; }
form { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 320px; }
#composer { max-width: none; flex-direction: row; }
input:not([type=file]) { padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); }
form > button, #enable-push { padding: 12px; border-radius: 10px; border: 0; background: var(--brand); color: #fff; font-weight: 600; min-height: 48px; cursor: pointer; }
.error { color: var(--warn); margin: 0; }
.panel { background: var(--panel); margin: 12px; padding: 14px; border-radius: 12px; display: flex; flex-direction: column; gap: 10px; }
.panel h2 { margin: 0; font-size: 17px; }
.panel p { margin: 0; }
.hint { color: var(--muted); font-size: 14px; }
.code { font-size: 30px; letter-spacing: 4px; font-weight: 700; text-align: center; }
