:root {
  --tg-bright: #3fe669;   /* Threema logo green */
  --tg: #1e7d43;          /* dark green: FAB / accents */
  --teal: #12a5a5;        /* own-profile avatar */
  --navpill: #b7ecc6;     /* selected bottom-nav pill */
  --appbar: #eef1f1;
  --chat-bg: #eceff1;
  --in-bubble: #ffffff;
  --out-bubble: #d7f5c2;
  --text: #16181a;
  --muted: #7c8388;
  --divider: #e6e8ea;
  --warn: #e53935;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: Roboto, "Segoe UI", system-ui, sans-serif; color: var(--text); font-size: 14px; -webkit-font-smoothing: antialiased; }
body { background: #fff; }
@media (min-width: 520px) { body { background: #d8dce0; } }

.phone {
  position: relative; width: 100%; max-width: 480px; height: 100dvh; margin: 0 auto;
  background: #fff; overflow: hidden; display: flex; flex-direction: column;
}
@media (min-width: 520px) { .phone { box-shadow: 0 0 24px rgba(0,0,0,.18); } }

#app { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.icon { width: 24px; height: 24px; fill: currentColor; display: block; }
.icon-btn { border: 0; background: none; color: #3a4247; padding: 8px; border-radius: 50%; cursor: pointer; display: inline-flex; }
.icon-btn:hover { background: rgba(0,0,0,.06); }

.avatar { border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 500; overflow: hidden; }
.avatar svg { width: 60%; height: 60%; fill: #fff; }
.avatar-32 { width: 32px; height: 32px; font-size: 14px; }
.avatar-40 { width: 40px; height: 40px; font-size: 16px; }
.avatar-48 { width: 48px; height: 48px; font-size: 18px; }
.avatar-88 { width: 88px; height: 88px; font-size: 34px; }
.avatar.teal { background: var(--teal); }

/* ---------- Top app bar ---------- */
.appbar {
  flex: 0 0 56px; display: flex; align-items: center; gap: 6px;
  padding: 0 6px 0 12px; background: var(--appbar); border-bottom: 1px solid var(--divider);
}
.appbar .warn { width: 22px; height: 22px; fill: var(--warn); flex-shrink: 0; }
.wordmark { display: flex; align-items: center; gap: 5px; font-size: 17px; letter-spacing: .5px; margin-left: 2px; }
.wordmark b { font-weight: 800; }
.wordmark .ed { font-weight: 400; }
.wordmark svg { width: 15px; height: 15px; }
.appbar .spacer { flex: 1; }

/* ---------- Tabs body ---------- */
.body { flex: 1; position: relative; overflow: hidden; }
.tab { position: absolute; inset: 0; overflow-y: auto; display: none; }
#app.view-chats .tab-chats { display: block; }
#app.view-contacts .tab-contacts { display: block; }
#app.view-profile .tab-profile { display: block; }
.tab::-webkit-scrollbar { width: 6px; }
.tab::-webkit-scrollbar-thumb { background: rgba(0,0,0,.2); border-radius: 3px; }

/* chat rows */
.row { display: flex; align-items: center; gap: 14px; padding: 0 16px; height: 72px; cursor: pointer; }
.row:hover { background: #f5f6f6; }
.rbody { flex: 1; min-width: 0; border-bottom: 1px solid var(--divider); height: 100%; display: flex; flex-direction: column; justify-content: center; gap: 3px; }
.row:last-child .rbody { border-bottom: 0; }
.rtop, .rbot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.rtop .name { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rtop .time { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.rbot .prev { font-size: 13.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 4px; }
.prev .tick { width: 15px; height: 15px; flex-shrink: 0; }
.tick.read { fill: var(--tg); }
.tick.delivered, .tick.sent { fill: #9aa0a6; }
.badge { background: var(--tg); color: #fff; font-weight: 600; font-size: 12px; min-width: 20px; height: 20px; border-radius: 10px; padding: 0 6px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

/* contacts */
.invite { display: flex; justify-content: center; padding: 14px 0 6px; }
.invite button {
  display: inline-flex; align-items: center; gap: 8px; background: #fff;
  border: 1px solid #cfd4d8; border-radius: 22px; padding: 9px 20px;
  font-size: 15px; color: var(--text); cursor: pointer;
}
.invite svg { width: 20px; height: 20px; fill: #3a4247; }
.crow { display: flex; align-items: center; gap: 12px; padding: 10px 16px 10px 8px; cursor: pointer; }
.crow:hover { background: #f5f6f6; }
.crow .sect { width: 16px; text-align: center; color: var(--tg); font-size: 13px; font-weight: 600; flex-shrink: 0; }
.cbody { flex: 1; min-width: 0; }
.cname { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.csub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cright { text-align: right; flex-shrink: 0; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.cid { font-size: 12px; color: var(--muted); font-family: "Roboto Mono", ui-monospace, monospace; }

.vdots { display: inline-flex; gap: 4px; }
.vd { width: 7px; height: 7px; border-radius: 50%; background: #cfd4d8; }

/* profile */
.profile { padding: 24px 0 0; }
.profile-top { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 8px 16px 24px; }
.pname { font-size: 20px; font-weight: 500; }
.pid { font-size: 14px; color: var(--muted); font-family: "Roboto Mono", ui-monospace, monospace; }
.prow { display: flex; justify-content: space-between; gap: 16px; padding: 14px 20px; border-top: 1px solid var(--divider); }
.prow span { color: var(--muted); }
.prow b { font-weight: 500; text-align: right; }
.prow b.mono { font-family: "Roboto Mono", ui-monospace, monospace; font-weight: 400; }

/* ---------- Bottom navigation ---------- */
.bottomnav { flex: 0 0 66px; display: flex; background: var(--appbar); border-top: 1px solid var(--divider); }
.bottomnav button { flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); cursor: pointer; font-size: 12px; padding-top: 8px; }
.bottomnav .pill { display: flex; align-items: center; justify-content: center; width: 60px; height: 30px; border-radius: 16px; }
.bottomnav svg { width: 24px; height: 24px; fill: currentColor; }
.bottomnav button.active { color: var(--text); font-weight: 500; }
.bottomnav button.active .pill { background: var(--navpill); }
.bottomnav button.active svg { fill: #0b3d1c; }

/* ---------- FAB ---------- */
.fab {
  position: absolute; right: 16px; bottom: 82px; background: var(--tg); color: #fff; border: 0;
  border-radius: 16px; height: 48px; padding: 0 20px 0 16px;
  display: inline-flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 600;
  box-shadow: 0 3px 8px rgba(0,0,0,.28); cursor: pointer; z-index: 6;
}
.fab svg { width: 22px; height: 22px; fill: #fff; }
#app.view-profile .fab { display: none; }

/* ---------- Conversation ---------- */
.conversation { position: absolute; inset: 0; background: var(--chat-bg); display: none; flex-direction: column; z-index: 8; }
.conversation.open { display: flex; }
.conv-header { flex: 0 0 56px; display: flex; align-items: center; gap: 8px; padding: 0 6px; background: var(--appbar); border-bottom: 1px solid var(--divider); }
.conv-header .peer { flex: 1; min-width: 0; }
.conv-header .peer .name-wrap { display: flex; align-items: center; gap: 6px; }
.conv-header .peer .name { font-size: 16px; }
.conv-header .peer .id { font-size: 12.5px; color: var(--muted); font-family: "Roboto Mono", ui-monospace, monospace; }

.messages { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,.2); border-radius: 3px; }
.pill { align-self: center; background: #fff; color: #6b7178; font-size: 12.5px; padding: 5px 12px; border-radius: 12px; box-shadow: 0 1px 1px rgba(0,0,0,.08); margin: 6px 0; }
.pill.enc { background: #eaf9ee; color: #3c6b4a; text-align: center; max-width: 92%; line-height: 1.4; }
.pill.enc svg { width: 11px; height: 11px; vertical-align: -1px; margin-right: 4px; fill: var(--tg); }
.msg { display: flex; max-width: 100%; }
.msg.in { justify-content: flex-start; }
.msg.out { justify-content: flex-end; }
.bubble { position: relative; max-width: 78%; padding: 6px 9px 8px; border-radius: 10px; box-shadow: 0 1px 1px rgba(0,0,0,.1); font-size: 14.2px; line-height: 19px; word-wrap: break-word; }
.msg.in .bubble { background: var(--in-bubble); border-top-left-radius: 2px; }
.msg.out .bubble { background: var(--out-bubble); border-top-right-radius: 2px; }
.msg.in .bubble::before { content: ""; position: absolute; top: 0; left: -7px; border-top: 7px solid var(--in-bubble); border-left: 7px solid transparent; }
.msg.out .bubble::before { content: ""; position: absolute; top: 0; right: -7px; border-top: 7px solid var(--out-bubble); border-right: 7px solid transparent; }
.bubble .sender { font-size: 12.8px; font-weight: 600; margin-bottom: 2px; }
.bubble .meta { float: right; margin: 8px 0 -4px 10px; font-size: 11px; color: var(--muted); display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.bubble .meta .tick { width: 15px; height: 15px; }

.composer { min-height: 60px; background: #f6f7f8; border-top: 1px solid var(--divider); display: flex; align-items: center; padding: 8px 10px; gap: 6px; }
.composer .input { flex: 1; background: #fff; border: 1px solid var(--divider); border-radius: 20px; padding: 9px 14px; color: var(--muted); font-size: 15px; }
.send { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--tg); color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.send svg { width: 22px; height: 22px; fill: #fff; }

/* ---------- Install popup (Google Play style, mobile only) ---------- */
.overlay { position: absolute; inset: 0; background: rgba(32,33,36,.6); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.overlay[hidden] { display: none; }
.sheet { background: #fff; width: 100%; border-radius: 20px 20px 0 0; padding: 20px 20px 16px; position: relative; box-shadow: 0 -4px 24px rgba(0,0,0,.3); animation: sheet-up .25s ease; color: #202124; }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-close { position: absolute; top: 12px; right: 14px; border: 0; background: none; font-size: 22px; color: #5f6368; cursor: pointer; line-height: 1; padding: 4px 8px; }
.ps-head { display: flex; gap: 16px; align-items: center; padding-right: 24px; }
.ps-icon { width: 60px; height: 60px; border-radius: 14px; flex-shrink: 0; border: 1px solid #eee; }
.ps-name { font-size: 20px; font-weight: 500; line-height: 1.2; }
.ps-dev { font-size: 14px; color: #01875f; margin-top: 3px; }
.ps-tags { font-size: 12px; color: #5f6368; margin-top: 2px; }
.ps-meta { display: flex; margin: 18px 0 16px; }
.ps-cell { flex: 1; text-align: center; border-right: 1px solid #e8eaed; }
.ps-cell:last-child { border-right: 0; }
.ps-cell .v { font-size: 14px; font-weight: 600; color: #202124; display: inline-flex; align-items: center; gap: 2px; min-height: 18px; }
.ps-cell .v .star { width: 14px; height: 14px; fill: #202124; }
.ps-cell .l { font-size: 11px; color: #5f6368; margin-top: 4px; }
.ps-cell .age { border: 1.4px solid #5f6368; color: #5f6368; border-radius: 3px; font-size: 11px; padding: 1px 4px; }
.ps-install { display: block; width: 100%; border: 0; background: #01875f; color: #fff; font-size: 15px; font-weight: 600; padding: 11px; border-radius: 100px; cursor: pointer; }
.ps-hint { margin: 12px 2px 0; font-size: 13px; color: #5f6368; line-height: 1.45; }
.ps-shots { display: flex; gap: 10px; overflow-x: auto; margin-top: 18px; padding-bottom: 4px; }
.shot { width: 104px; flex: 0 0 auto; border: 1px solid #e8eaed; border-radius: 10px; overflow: hidden; }
.shot-top { height: 22px; background: var(--tg); }
.shot-body { height: 160px; background: var(--chat-bg); padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.shot .b { height: 14px; border-radius: 6px; }
.shot .b.s { height: 10px; }
.shot .b.in { width: 72%; background: #fff; }
.shot .b.out { width: 62%; align-self: flex-end; background: var(--out-bubble); }
