:root {
  --bg: #eae6df; --panel: #fff; --bar: #f0f2f5; --line: #e9edef;
  --text: #111b21; --muted: #667781; --in: #fff; --out: #d9fdd3;
  --accent: #00a884; --pill: #fff; --wall: #efeae2; --doodle: rgba(0,0,0,.035);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1317; --panel: #111b21; --bar: #202c33; --line: #222d34;
    --text: #e9edef; --muted: #8696a0; --in: #202c33; --out: #005c4b;
    --pill: #182229; --wall: #0b141a; --doodle: rgba(255,255,255,.025);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14.2px/1.4 "Segoe UI", -apple-system, BlinkMacSystemFont, Helvetica, Arial, sans-serif;
}
.app { display: flex; height: 100vh; height: 100dvh; max-width: 1600px; margin: 0 auto; }
@media (min-width: 1441px) { .app { height: calc(100vh - 38px); margin-top: 19px; box-shadow: 0 6px 18px rgba(11,20,26,.05); } }

.bar { height: 59px; flex: none; display: flex; align-items: center; gap: 13px; padding: 0 16px; background: var(--bar); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: #6b7c85; font-size: 18px; font-weight: 600; color: #fff;
}
.avatar.me { background: var(--accent); font-size: 17px; font-weight: 600; }
.avatar.big { width: 49px; height: 49px; font-size: 21px; }

.sidebar { width: 30%; min-width: 300px; max-width: 420px; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); }
.brand { font-weight: 600; font-size: 17px; color: var(--accent); }
.search { padding: 8px 12px; border-bottom: 1px solid var(--line); }
.search input { width: 100%; border: 0; border-radius: 8px; padding: 8px 14px; background: var(--bar); color: var(--text); font: inherit; }
.chat-row { display: flex; align-items: center; gap: 13px; padding: 0 15px; height: 72px; cursor: default; }
.chat-row.active { background: var(--bar); }
.row-body { flex: 1; min-width: 0; border-bottom: 1px solid var(--line); height: 100%; display: flex; flex-direction: column; justify-content: center; }
.row-top { display: flex; justify-content: space-between; align-items: baseline; }
.row-name { font-size: 17px; }
.row-time, .row-preview { font-size: 12.5px; color: var(--muted); }
.row-preview { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; background: var(--wall); }
.chat .bar { border-left: 1px solid var(--line); }
.title .name { font-size: 16px; }
.title .sub { font-size: 13px; color: var(--muted); }

.scroller {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column-reverse;
  padding: 8px 6% 12px; overflow-anchor: none;
  background-color: var(--wall);
  background-image: radial-gradient(var(--doodle) 1.5px, transparent 1.6px), radial-gradient(var(--doodle) 1.5px, transparent 1.6px);
  background-size: 28px 28px; background-position: 0 0, 14px 14px;
}
.sentinel { display: grid; place-items: center; min-height: 48px; }
.sentinel.done { min-height: 0; }
.spinner { width: 22px; height: 22px; border: 2.5px solid var(--muted); border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; opacity: .6; }
.sentinel.done .spinner { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.day, .day-float span {
  align-self: center; margin: 10px 0; padding: 5px 12px; border-radius: 7.5px;
  background: var(--pill); color: var(--muted); font-size: 12.5px; box-shadow: 0 1px .5px rgba(11,20,26,.13);
}
.day { text-transform: uppercase; }
.day-float { position: absolute; top: 67px; left: 0; right: 0; display: flex; justify-content: center; z-index: 2; pointer-events: none; opacity: 0; transition: opacity .3s; }
.day-float span { margin: 0; text-transform: uppercase; }
.day-float.show { opacity: 1; }

.msg { display: flex; margin-top: 2px; }
.msg.tail { margin-top: 10px; }
.msg.out { justify-content: flex-end; }
.bubble {
  position: relative; max-width: min(65%, 560px); padding: 6px 7px 8px 9px; border-radius: 7.5px;
  background: var(--in); box-shadow: 0 1px .5px rgba(11,20,26,.13); word-wrap: break-word; overflow-wrap: anywhere;
}
.out .bubble { background: var(--out); }
.tail .bubble::before {
  content: ""; position: absolute; top: 0; width: 8px; height: 13px; background: inherit;
}
.in.tail .bubble { border-top-left-radius: 0; }
.out.tail .bubble { border-top-right-radius: 0; }
.in.tail .bubble::before { left: -8px; clip-path: polygon(0 0, 100% 0, 100% 100%); }
.out.tail .bubble::before { right: -8px; clip-path: polygon(0 0, 100% 0, 0 100%); }
.text { white-space: pre-wrap; }
.text a { color: #027eb5; }
@media (prefers-color-scheme: dark) { .text a { color: #53bdeb; } }
.meta { float: right; margin: 6px -2px -5px 10px; font-size: 11px; color: var(--muted); white-space: nowrap; line-height: 15px; }
.out .meta::after { content: " ✓✓"; color: #53bdeb; letter-spacing: -3px; margin-right: 3px; }
.media { display: flex; align-items: center; gap: 8px; padding: 10px 12px; margin: -2px -3px 4px -5px; border-radius: 6px; background: rgba(0,0,0,.05); color: var(--muted); font-size: 13.5px; }
.media .ic { font-size: 22px; }
.media.caption-only { margin-bottom: 0; }
.deleted { color: var(--muted); font-style: italic; }
.big-emoji { font-size: 34px; line-height: 1.2; }

.to-bottom {
  position: absolute; right: 22px; bottom: 80px; width: 42px; height: 42px; border-radius: 50%; border: 0;
  background: var(--pill); color: var(--muted); font-size: 22px; cursor: pointer; box-shadow: 0 1px 3px rgba(11,20,26,.25);
  opacity: 0; pointer-events: none; transition: opacity .2s; line-height: 1;
}
.to-bottom.show { opacity: 1; pointer-events: auto; }

.composer { flex: none; min-height: 62px; display: flex; align-items: center; gap: 16px; padding: 5px 16px; background: var(--bar); color: var(--muted); font-size: 22px; }
.fake-input { flex: 1; padding: 10px 14px; border-radius: 8px; background: var(--panel); font-size: 15px; }

.icon-btn { margin-left: auto; border: 0; background: none; color: var(--muted); cursor: pointer; padding: 8px; border-radius: 50%; display: grid; place-items: center; font-size: 18px; }
.icon-btn:hover { background: rgba(0,0,0,.06); }
.search-panel .icon-btn { margin-left: 0; }
.search-panel { display: none; width: 30%; min-width: 300px; max-width: 420px; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line); }
.search-panel.open { display: flex; }
.search-panel .bar { gap: 20px; font-size: 16px; }
.search-panel input { outline: none; }
.search-status { padding: 14px 20px 8px; color: var(--muted); font-size: 13.5px; }
.search-results { flex: 1; overflow-y: auto; }
.hit { display: block; width: 100%; text-align: left; border: 0; background: none; color: inherit; font: inherit; cursor: pointer; padding: 12px 20px; border-bottom: 1px solid var(--line); }
.hit:hover, .hit.sel { background: var(--bar); }
.hit-date { font-size: 12.5px; color: var(--muted); margin-bottom: 3px; }
.hit-text { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--muted); }
.hit-text mark { background: none; color: var(--accent); font-weight: 600; }
.hit-text .you { color: var(--muted); }
.msg.flash .bubble { animation: flash 1.6s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: 0 1px .5px rgba(11,20,26,.13); } }
@media (max-width: 1100px) { .searching .sidebar { display: none; } }

@media (max-width: 760px) {
  .search-panel { position: fixed; inset: 0; width: auto; max-width: none; z-index: 5; }
  .sidebar { display: none; }
  .scroller { padding: 8px 3% 12px; }
  .bubble { max-width: 85%; }
}

.lock { display: none; }
.locked .app { display: none; }
.locked .lock {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  min-height: 100vh; min-height: 100dvh; padding: 24px; text-align: center;
}
.lock-logo { font-size: 64px; }
.lock h1 { margin: 0; font-weight: 400; font-size: 30px; color: var(--accent); }
.lock p { margin: 0 0 8px; color: var(--muted); }
.lock input {
  width: min(320px, 100%); padding: 12px 16px; border: 0; border-bottom: 2px solid var(--accent); border-radius: 8px 8px 0 0;
  background: var(--panel); color: var(--text); font: inherit; font-size: 16px; outline: none; text-align: center;
}
.lock button {
  padding: 10px 32px; border: 0; border-radius: 24px; background: var(--accent); color: #fff; font: inherit; font-weight: 600; cursor: pointer;
}
.lock.busy button { opacity: .6; pointer-events: none; }
.lock.busy button::after { content: "…"; }
.lock-err { min-height: 20px; color: #ea0038; font-size: 13.5px; }
.lock.shake input { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
