:root {
  --bg: #fff; --fg: #111; --muted: #6b6b6b; --line: #e3e3e3; --accent: #2a6df4; --bubble: #f1f1f3; --mine: #dbe7ff;
  --warn-bg: #fff4e5; --warn-fg: #8a4b00;
  font: 15px/1.4 system-ui, -apple-system, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121212; --fg: #eee; --muted: #9a9a9a; --line: #2a2a2a; --accent: #6b9cff; --bubble: #1f1f1f; --mine: #1f2f52;
    --warn-bg: #3a2a10; --warn-fg: #ffcf8a; }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--fg); height: var(--app-height, 100dvh); overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent; overscroll-behavior: none;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { font-size: 16px; } /* below 16px iOS zooms the page on focus */
input, select, textarea { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; min-width: 0; }
button { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 7px 13px; cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }
button.quiet { background: transparent; color: var(--muted); padding: 4px 6px; }
button.quiet:hover { color: var(--fg); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; }
form { display: flex; gap: 6px; }
form input, form select { flex: 1; }
ul.plain { list-style: none; margin: 0; padding: 0; font-size: 13px; }
ul.plain li { padding: 6px 0; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 6px; }
code { font-size: 11px; color: var(--muted); word-break: break-all; }
.warning { background: var(--warn-bg); color: var(--warn-fg); margin: 0; padding: 8px 16px; font-size: 13px; }

.gate { display: grid; place-items: center; height: 100%; overflow-y: auto; padding: 16px; }
.gate form { flex-direction: column; width: min(360px, 100%); }
.gate h1 { margin: 0 0 4px; font-size: 20px; }
.gate p { margin: 0 0 4px; }
#code { letter-spacing: .2em; text-align: center; font-size: 22px; }
.recovery { display: block; font: 600 17px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .04em;
  padding: 12px; border: 1px dashed var(--line); border-radius: 8px; text-align: center; word-spacing: .2em; user-select: all; }
#unlock-key { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; }
.check input { flex: none; margin-top: 3px; }

#app { display: grid; grid-template-columns: 270px 1fr; height: 100%; }
nav { border-right: 1px solid var(--line); padding: 12px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
nav header { display: flex; justify-content: space-between; align-items: center; word-break: break-all; }
nav details summary { cursor: pointer; color: var(--muted); font-size: 13px; padding: 4px 0; }
#rooms { list-style: none; margin: 0; padding: 0; flex: 1; }
#rooms li { padding: 8px; border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; gap: 6px; }
#rooms li:hover { background: var(--bubble); }
#rooms li.active { background: var(--mine); }
#rooms .flag { color: var(--warn-fg); }
#rooms .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#rooms li.unread .name { font-weight: 600; }
#rooms .count { background: var(--accent); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; align-self: center; }
#invite-msg:empty { display: none; }
#status { margin-left: auto; margin-right: 6px; white-space: nowrap; }
.warn { color: var(--warn-fg); }
#people li.pending { background: var(--warn-bg); border-radius: 6px; padding: 6px; }
#people .actions { display: flex; gap: 4px; flex: none; }
body.typing { padding-bottom: 0; }

#room, #empty { display: flex; flex-direction: column; height: 100%; min-width: 0; min-height: 0; }
#empty { align-items: center; justify-content: center; }
#room header { display: flex; align-items: center; gap: 6px; padding: 10px 16px 4px; }
#room h2 { margin: 0; font-size: 17px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#back { display: none; font-size: 22px; line-height: 1; }
#members { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 16px 6px; }
.chip { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; background: var(--bubble); border-radius: 999px; padding: 2px 4px 2px 10px; }
.chip button { padding: 0 6px; font-size: 14px; line-height: 1; }
.chip.me { padding-right: 10px; }
#add-member { padding: 0 16px 8px; border-bottom: 1px solid var(--line); }
#messages { list-style: none; margin: 0; padding: 12px 16px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; min-height: 0; }
#messages li { max-width: 75%; padding: 6px 10px; border-radius: 12px; background: var(--bubble); white-space: pre-wrap; overflow-wrap: anywhere; }
#messages li.mine { align-self: flex-end; background: var(--mine); }
#messages li a { color: var(--accent); text-decoration: underline; overflow-wrap: anywhere; }
#messages li .who { display: block; font-size: 11px; color: var(--muted); }
#messages li.locked { font-style: italic; color: var(--muted); }
#messages li.bad { font-style: italic; color: var(--warn-fg); background: var(--warn-bg); }
#messages li.sys { align-self: center; background: none; color: var(--muted); font-size: 12px; text-align: center; max-width: 90%; }
#messages li.more { align-self: center; background: none; padding: 0; }
#messages li.day { align-self: center; background: none; color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; padding: 10px 0 2px; }
#messages li .time { display: block; font-size: 10px; color: var(--muted); text-align: right; margin-top: 1px; }
#compose { padding: 10px 16px; border-top: 1px solid var(--line); align-items: flex-end; }
#compose textarea { flex: 1; resize: none; max-height: 30vh; line-height: 1.35; }

@media (max-width: 700px) {
  #app { grid-template-columns: 1fr; }
  nav { border-right: 0; }
  #app.in-room nav, #app:not(.in-room) #room, #app:not(.in-room) #empty, #app.in-room #empty { display: none !important; }
  #back { display: block; }
  #messages li { max-width: 88%; }
}
.room-actions { display: flex; gap: 8px; padding: 0 16px; }
.room-actions:has(button:not([hidden])) { padding: 6px 16px; }
#unlock-sessions-panel summary { cursor: pointer; color: var(--muted); font-size: 13px; }
