:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  --page: #f5f6f4;
  --surface: #fff;
  --subtle: #f1f3f0;
  --text: #202823;
  --muted: #717b74;
  --line: #e7ebe6;
  --accent: #28764e;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: var(--page); color: var(--text); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .55; cursor: wait; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
.muted { color: var(--muted); }
.error { color: #ad413b; }

.login { width: min(100%, 440px); margin: 12vh auto 0; padding: 24px; }
.login h1 { font-size: 28px; font-weight: 650; letter-spacing: -.025em; margin: 0 0 10px; }
.login p { color: var(--muted); line-height: 1.45; }
.login form { display: grid; gap: 12px; margin-top: 32px; }
.login label { font-weight: 600; }
.login input { width: 100%; padding: 14px; border: 1px solid #cdd7ce; border-radius: 10px; background: var(--surface); font-size: 16px; }

.primary, .secondary { min-height: 46px; padding: 11px 16px; border-radius: 10px; font-weight: 600; }
.primary { color: #fff; background: var(--accent); border: 1px solid var(--accent); }
.secondary { color: var(--accent); background: var(--surface); border: 1px solid #cddbd0; }
.plain { min-height: 44px; border: 0; background: transparent; color: var(--accent); padding: 10px; }
.plain:active, .secondary:active { background: var(--subtle); }

.app {
  display: flex;
  flex-direction: column;
  width: min(100%, 680px);
  min-width: 0;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--surface);
}
.topbar { display: flex; flex: none; align-items: center; justify-content: space-between; gap: 12px; padding: max(10px, env(safe-area-inset-top)) 16px 8px; border-bottom: 1px solid var(--line); }
.topbar-title { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 19px; font-weight: 650; letter-spacing: -.02em; }
.accounts-bar { display: flex; flex: none; gap: 8px; align-items: center; min-width: 0; padding: 8px 14px; border-bottom: 1px solid var(--line); }
.accounts-bar select { min-width: 0; flex: 1; padding: 11px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--subtle); color: var(--text); font-size: 16px; }
.accounts-bar .add { flex: none; white-space: nowrap; font-weight: 600; }

.empty, .pair { flex: 1; min-width: 0; overflow: auto; padding: 30px 22px; }
.empty h2, .pair h2 { margin: 0 0 10px; font-size: 21px; font-weight: 650; }
.empty p, .pair p { color: var(--muted); line-height: 1.5; }
.qr-wrap { display: flex; align-items: center; justify-content: center; min-height: 238px; max-width: 260px; margin: 20px auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.qr-wrap img { max-width: 226px; max-height: 226px; width: 100%; image-rendering: pixelated; }
.pair .secondary, .pair .delete { display: block; width: 100%; margin-top: 14px; }
.delete { padding: 12px; border: 0; background: transparent; color: #a64a45; }

.chat-list, .conversation { display: flex; flex: 1; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.list-title { display: flex; flex: none; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; padding: 10px 14px 4px; }
.list-title h2 { margin: 0; font-size: 17px; font-weight: 650; }
.list-title details { position: relative; }
.list-title summary { display: grid; place-items: center; width: 42px; height: 38px; list-style: none; cursor: pointer; color: var(--muted); font-size: 23px; letter-spacing: -.08em; }
.list-title summary::-webkit-details-marker { display: none; }
.actions-popover { position: absolute; top: 40px; right: 0; z-index: 5; width: 185px; padding: 5px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: 0 6px 18px #0002; }
.actions-popover button { display: block; width: 100%; min-height: 42px; padding: 9px 11px; border: 0; border-radius: 6px; background: transparent; color: var(--text); text-align: left; font-size: 14px; }
.actions-popover button:active { background: var(--subtle); }
.actions-popover #remove-connected { color: #a64a45; }
.chats { flex: 1; min-width: 0; max-width: 100%; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; }
.chat-row { display: flex; align-items: center; gap: 12px; width: 100%; max-width: 100%; min-width: 0; min-height: 72px; overflow: hidden; padding: 12px 16px; border: 0; border-bottom: 1px solid var(--line); background: var(--surface); color: inherit; text-align: left; }
.chat-row:active { background: var(--subtle); }
.avatar { display: grid; flex: none; place-items: center; width: 42px; height: 42px; border-radius: 50%; background: #e9eeea; color: #486b54; font-size: 17px; font-weight: 650; }
.chat-copy { display: block; flex: 1 1 0; min-width: 0; max-width: 100%; overflow: hidden; }
.chat-name, .chat-preview { display: block; width: 100%; max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chat-name { font-size: 15px; font-weight: 600; }
.chat-preview { margin-top: 4px; color: var(--muted); font-size: 13px; }
.badge { flex: none; min-width: 22px; padding: 3px 6px; border-radius: 12px; background: var(--accent); color: #fff; text-align: center; font-size: 11px; font-weight: 700; }

.chat-header { display: flex; flex: none; align-items: center; gap: 6px; min-width: 0; min-height: 54px; padding: 0 10px; border-bottom: 1px solid var(--line); }
.back { flex: none; min-width: 44px; font-size: 29px; line-height: 1; }
.chat-title { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 16px; font-weight: 600; }
.messages { display: flex; flex: 1; flex-direction: column; gap: 8px; min-width: 0; min-height: 0; overflow-x: hidden; overflow-y: auto; padding: 16px 12px; background: var(--page); overscroll-behavior: contain; }
.bubble { align-self: flex-start; max-width: 88%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 13px 13px 13px 4px; background: var(--surface); white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.4; }
.bubble.mine { align-self: flex-end; border-color: #d6e8da; border-radius: 13px 13px 4px 13px; background: #e6f3e8; }
.bubble img { display: block; max-width: 100%; max-height: 300px; margin: 6px 0; border-radius: 7px; }
.bubble audio, .bubble video { display: block; max-width: 100%; margin: 6px 0; }
.bubble .unavailable { color: var(--muted); font-size: 13px; }
.bubble time { display: block; margin-top: 5px; color: var(--muted); text-align: right; font-size: 11px; }
.composer { display: flex; flex: none; align-items: end; gap: 8px; min-width: 0; padding: 9px 10px max(11px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface); }
.composer textarea { flex: 1; min-width: 0; max-height: 120px; resize: none; padding: 10px 12px; border: 1px solid #d3ddd4; border-radius: 13px; background: var(--page); color: var(--text); font-size: 16px; line-height: 1.4; }
.attach, .send { display: grid; flex: none; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%; }
.attach { background: var(--subtle); color: var(--text); font-size: 27px; }
.send { background: var(--accent); color: #fff; font-size: 19px; }
.notice { position: fixed; bottom: 90px; left: 50%; width: max-content; max-width: 90vw; padding: 12px 16px; transform: translateX(-50%); border-radius: 9px; background: #27352b; color: #fff; box-shadow: 0 5px 16px #0002; }

@media (min-width: 700px) { .app { border-right: 1px solid var(--line); border-left: 1px solid var(--line); } }
