:root {
  --panel: #ffffff;
  --header-bg: #f0f2f5;
  --hover: #f5f6f6;
  --active: #f0f2f5;
  --search-bg: #f0f2f5;
  --in-bubble: #ffffff;
  --out-bubble: #d9fdd3;
  --text: #111b21;
  --muted: #667781;
  --divider: #e9edef;
  --check-blue: #53bdeb;
  --accent: #00a884;
  --badge: #25d366;
  --wallpaper: #efeae2;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", Helvetica, "Helvetica Neue", system-ui, sans-serif;
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  height: 100%;
  background: var(--panel);
}

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

/* ---------- Sidebar ---------- */
.sidebar {
  width: 30%;
  min-width: 300px;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--divider);
}

.side-header {
  height: 59px;
  flex: 0 0 59px;
  background: var(--header-bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}
.side-header .actions { display: flex; align-items: center; gap: 2px; }

.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; opacity: .9; }
.avatar-40 { width: 40px; height: 40px; font-size: 16px; }
.avatar-49 { width: 49px; height: 49px; font-size: 19px; }

.search-wrap {
  padding: 8px 12px;
  border-bottom: 1px solid var(--divider);
  display: flex;
  align-items: center;
  gap: 8px;
}
.search {
  flex: 1;
  background: var(--search-bg);
  border-radius: 8px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  height: 35px;
  gap: 24px;
}
.search svg { width: 18px; height: 18px; fill: #54656f; }
.search input {
  border: 0;
  background: none;
  outline: none;
  flex: 1;
  font-size: 14px;
  color: var(--text);
}
.filter-btn svg { width: 20px; height: 20px; }

.chats {
  flex: 1;
  overflow-y: auto;
}
.chats::-webkit-scrollbar { width: 6px; }
.chats::-webkit-scrollbar-thumb { background: rgba(0,0,0,.2); border-radius: 3px; }

.chat-row {
  display: flex;
  align-items: center;
  padding: 0 16px 0 13px;
  height: 72px;
  cursor: pointer;
  gap: 15px;
}
.chat-row:hover { background: var(--hover); }
.chat-row.active { background: var(--active); }

.chat-row .body {
  flex: 1;
  min-width: 0;
  border-top: 1px solid var(--divider);
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
}
.chat-row:first-child .body { border-top: 0; }
.row-top, .row-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row-top .name { font-size: 17px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-top .time { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.chat-row.unread .row-top .time { color: var(--accent); }
.row-bottom .preview {
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 4px;
}
.preview .tick { fill: var(--check-blue); width: 16px; height: 16px; flex-shrink: 0; }
.badge {
  background: var(--badge);
  color: #fff;
  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;
}
.muted-icon { width: 18px; height: 18px; fill: var(--muted); flex-shrink: 0; }

/* ---------- Chat panel ---------- */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  min-width: 0;
}

.chat-header {
  height: 59px;
  flex: 0 0 59px;
  background: var(--header-bg);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 15px;
  z-index: 2;
}
.chat-header .peer { flex: 1; min-width: 0; }
.chat-header .peer .name { font-size: 16px; color: var(--text); }
.chat-header .peer .status { font-size: 13px; color: var(--muted); }
.chat-header .actions { display: flex; align-items: center; gap: 2px; }
.back { display: none; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 6%;
  background-color: var(--wallpaper);
  background-image: url(/wallpaper.svg);
  background-size: 480px;
  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: #ffffff;
  color: #54656f;
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: 8px;
  box-shadow: 0 1px 0.5px rgba(11,20,26,.13);
  margin: 6px 0;
}
.pill.enc {
  background: #ffeecd;
  color: #54656f;
  text-align: center;
  max-width: 90%;
  line-height: 1.35;
}
.pill.enc svg { width: 11px; height: 11px; vertical-align: -1px; margin-right: 3px; fill: #54656f; }

.msg { display: flex; max-width: 100%; }
.msg.in { justify-content: flex-start; }
.msg.out { justify-content: flex-end; }

.bubble {
  position: relative;
  max-width: 65%;
  padding: 6px 9px 8px 9px;
  border-radius: 8px;
  box-shadow: 0 1px 0.5px rgba(11,20,26,.13);
  font-size: 14.2px;
  line-height: 19px;
  color: var(--text);
  word-wrap: break-word;
}
.msg.in .bubble { background: var(--in-bubble); border-top-left-radius: 0; }
.msg.out .bubble { background: var(--out-bubble); border-top-right-radius: 0; }
.msg.in .bubble::before {
  content: ""; position: absolute; top: 0; left: -8px;
  border-top: 8px solid var(--in-bubble); border-left: 8px solid transparent;
}
.msg.out .bubble::before {
  content: ""; position: absolute; top: 0; right: -8px;
  border-top: 8px solid var(--out-bubble); border-right: 8px solid transparent;
}
.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: 16px; height: 16px; fill: var(--check-blue); }
.bubble .sender { font-size: 12.8px; font-weight: 500; margin-bottom: 2px; }
.tick.gray { fill: #8696a0; }

/* ---------- Composer ---------- */
.composer {
  min-height: 62px;
  background: var(--header-bg);
  display: flex;
  align-items: center;
  padding: 8px 16px;
  gap: 8px;
}
.composer .input {
  flex: 1;
  background: #fff;
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--muted);
  font-size: 15px;
}

/* ---------- Install pill ---------- */
.install-fab {
  position: absolute;
  right: 20px;
  bottom: 78px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 22px;
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
  cursor: pointer;
  display: none;
  align-items: center;
  gap: 8px;
  z-index: 5;
}
.install-fab svg { width: 18px; height: 18px; fill: #fff; }
.install-fab.show { display: inline-flex; }

/* ---------- Install popup (Google Play style) ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(32, 33, 36, .6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.overlay[hidden] { display: none; }
.sheet {
  background: #fff;
  width: 100%;
  max-width: 440px;
  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;
  font-family: Roboto, "Segoe UI", system-ui, sans-serif;
  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; }
.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;
  font-family: inherit;
}
.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: 116px;
  flex: 0 0 auto;
  border: 1px solid #e8eaed;
  border-radius: 10px;
  overflow: hidden;
}
.shot-top { height: 24px; background: #008069; }
.shot-body {
  height: 176px;
  background: var(--wallpaper);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.shot .b { height: 15px; border-radius: 6px; }
.shot .b.s { height: 11px; }
.shot .b.in { width: 72%; background: #fff; }
.shot .b.out { width: 62%; align-self: flex-end; background: #d9fdd3; }

@media (min-width: 768px) {
  .overlay { align-items: center; }
  .sheet { border-radius: 16px; margin: 0 16px; animation: sheet-in .2s ease; }
  @keyframes sheet-in { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }
}

/* ---------- Mobile: list first, tap a chat to open it ---------- */
@media (max-width: 768px) {
  .sidebar { width: 100%; max-width: none; border-right: 0; }
  .chat { display: none; }
  #app.show-chat .sidebar { display: none; }
  #app.show-chat .chat { display: flex; }
  .back { display: inline-flex; }
}
