/* iMessage look: system font, blue/grey bubbles with tails. Dark only; own palette, not the house theme. */
:root {
  color-scheme: dark;
  --bg: #000000;
  --side: #1c1c1e;
  --bar: #1c1c1e;
  --fg: #ffffff;
  --sub: #98989f;
  --line: #38383a;
  --recv: #26262a;
  --sent: #0a73e5;
  --field-line: #4a4a4d;
  --fill: rgba(118, 118, 128, 0.24);
  --err: #ff6961;
  --av-top: #8a8f9e;
  --av-bottom: #5b6171;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; touch-action: manipulation; }
body {
  font: 15px/1.3 var(--font);
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
#app { height: 100%; }
/* slim dark scrollbars (desktop; iOS draws its own overlay bars) */
* { scrollbar-width: thin; scrollbar-color: #48484a transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #48484a; border-radius: 4px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #636366; background-clip: content-box; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--sent); outline-offset: 2px; }

/* Pinned to the visible area (set by `track_keyboard` in client.ere): iOS pans the page when the keyboard opens, and the pan drifts as messages arrive. */
.app { display: flex; position: fixed; left: 0; right: 0; top: var(--vvt, 0px); height: var(--vvh, 100dvh); }

/* sidebar */
.sidebar {
  position: relative;
  width: 320px;
  flex: none;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--side);
  border-right: 1px solid var(--line);
}
.sb-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 0 16px;
}
.me-btn { border-radius: 50%; }
.me-btn .av { width: 32px; height: 32px; font-size: 13px; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; color: var(--sent); border-radius: 50%; }
.sb-title { margin: 4px 16px 6px; font-size: 30px; line-height: 1.15; font-weight: 700; letter-spacing: -0.02em; }
.search {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 16px 8px;
  padding: 0 10px;
  height: 36px;
  border-radius: 10px;
  background: var(--fill);
  color: var(--sub);
}
.search:focus-within { outline: 2px solid var(--sent); }
.search-ic { display: grid; place-items: center; }
.search-input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 17px; }
.search-input::placeholder { color: var(--sub); opacity: 1; }
@media (pointer: coarse) { .convs-in { min-height: calc(100% + 1px); } } /* touch: always scrollable, so iOS bounces even a short list; with a mouse that would show a scrollbar for nothing */
.convs { flex: 1; overscroll-behavior-y: contain; -webkit-overflow-scrolling: touch; overflow-y: auto; min-height: 0; padding-bottom: env(safe-area-inset-bottom); }
.empty-list { text-align: center; color: var(--sub); margin: 32px 16px; }

.conv {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 8px;
  padding: 0 10px 0 6px;
  border-radius: 10px;
  min-height: 76px;
  cursor: pointer;
}
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.on { background: var(--sent); }
.conv .av { width: 48px; height: 48px; font-size: 19px; margin-right: 4px; }
.conv-body {
  flex: 1;
  min-width: 0;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
  border-bottom: 1px solid var(--line);
}
.conv-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.conv-name { font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { flex: none; font-size: 15px; color: var(--sub); }
.conv-last {
  font-size: 15px;
  line-height: 1.25;
  color: var(--sub);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.conv.active { background: var(--sent); }
.conv.active .conv-body { border-bottom-color: transparent; }
.conv.active .conv-name, .conv.active .conv-time, .conv.active .conv-last { color: #fff; }
.conv.active .dot.on { background: #fff; }

.av {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background-color: var(--av-bottom);
  background-image: linear-gradient(var(--av-top), var(--av-bottom));
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  text-transform: uppercase;
  user-select: none;
}
.av-lg { width: 44px; height: 44px; font-size: 17px; }

/* thread */
.thread { position: relative; flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.th-head {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 68px;
  padding: calc(env(safe-area-inset-top) + 6px) 56px 6px;
  background: var(--bar);
  border-bottom: 1px solid var(--line);
}
.th-who { cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; }
.th-name { font-size: 12px; max-width: 60vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.th-who .th-name::after { content: " \203A"; color: var(--sub); }
/* thread header: no bar, a picture and a name pill floating over the messages, like iOS */
.th-head.th-float { position: absolute; top: 0; left: 0; right: 0; z-index: 5; min-height: 0; align-items: flex-start; padding: calc(env(safe-area-inset-top) + 4px) 16px 20px; background: linear-gradient(var(--bg) 60%, transparent); border-bottom: 0; pointer-events: none; }
.th-float > * { pointer-events: auto; }
.th-float .back-btn { top: calc(env(safe-area-inset-top) + 4px); left: 16px; width: 40px; height: 40px; border-radius: 50%; background: rgba(44, 44, 46, 0.85); color: var(--fg); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
.th-float .th-who { gap: 0; }
.th-float .av-lg { width: 44px; height: 44px; font-size: 18px; }
.th-float .th-name { position: relative; margin-top: -6px; padding: 2px 10px; border-radius: 12px; background: rgba(44, 44, 46, 0.9); font-size: 12px; font-weight: 600; max-width: 50vw; }
.th-float ~ .scroller .msgs { padding-top: calc(env(safe-area-inset-top) + 84px); }
.compose-head .th-name { font-size: 16px; font-weight: 600; }
.back-btn { display: none; position: absolute; left: 6px; top: calc(env(safe-area-inset-top) + 14px); width: 40px; height: 40px; place-items: center; color: var(--sent); }
.cancel-btn { position: absolute; left: 16px; top: calc(env(safe-area-inset-top) + 24px); font-size: 17px; color: var(--sent); }
.to-row { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.to-label { color: var(--sub); font-size: 17px; }
.to-input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 17px; }
.to-input::placeholder { color: var(--sub); opacity: 1; }
.form-error { margin: 0; padding: 10px 16px; font-size: 14px; color: var(--err); }

.scroller { flex: 1; min-height: 0; overflow: hidden auto; display: flex; flex-direction: column-reverse; overscroll-behavior: contain; }
.msgs { flex: none; display: flex; flex-direction: column; justify-content: flex-end; min-height: 100%; padding: 8px 16px 6px; }
@media (pointer: coarse) { .msgs { min-height: calc(100% + 1px); } }
.m { display: flex; margin-top: 2px; }
.m.first { margin-top: 10px; }
.m.sent { justify-content: flex-end; }
.bubble {
  position: relative;
  max-width: min(75%, 560px);
  padding: 7px 14px 8px;
  border-radius: 18px;
  font-size: 17px;
  line-height: 1.25;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.sent .bubble { background: var(--sent); color: #fff; }
.recv .bubble { background: var(--recv); color: var(--fg); }
.tail .bubble::before, .tail .bubble::after { content: ""; position: absolute; bottom: 0; height: 18px; }
.sent.tail .bubble::before { right: -7px; width: 20px; background: var(--sent); border-bottom-left-radius: 16px 14px; }
.sent.tail .bubble::after { right: -26px; width: 26px; background: var(--bg); border-bottom-left-radius: 10px; }
.recv.tail .bubble::before { left: -7px; width: 20px; background: var(--recv); border-bottom-right-radius: 16px 14px; }
.recv.tail .bubble::after { left: -26px; width: 26px; background: var(--bg); border-bottom-right-radius: 10px; }
.stamp { text-align: center; font-size: 11px; color: var(--sub); margin: 14px 0 4px; }
.stamp-day { font-weight: 600; }
.stamp-clock { margin-left: 0.3em; }
.status { align-self: flex-end; margin: 3px 2px 0 0; font-size: 11px; font-weight: 600; color: var(--sub); }

.composer { flex: none; display: flex; align-items: flex-end; gap: 8px; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); background: var(--bg); }
.kb .composer { padding-bottom: 8px; }
.composer .pill { flex: 1; min-width: 0; }
.pill {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 38px;
  border: 1px solid var(--field-line);
  border-radius: 19px;
  background: var(--bg);
}
.pill:focus-within { border-color: var(--sent); }
.compose-input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 17px; padding: 7px 46px 7px 14px; }
.compose-input::placeholder { color: var(--sub); opacity: 1; }
.send {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--sent);
  color: #fff;
  transition: opacity 0.12s, transform 0.12s;
}
.send:not(.on) { opacity: 0; transform: scale(0.5); pointer-events: none; visibility: hidden; }

.empty-thread { flex: 1; display: grid; place-items: center; }
.empty-title { color: var(--sub); font-size: 15px; font-weight: 600; }

/* sign-in stand-in */
.login { height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 24px; }
.login-title { margin: 0; font-size: 34px; font-weight: 700; letter-spacing: -0.02em; }
.login-sub { margin: 0 0 8px; color: var(--sub); }
.google-btn { display: block; box-sizing: border-box; width: min(100%, 320px); padding: 12px 16px; border-radius: 22px; background: #fff; color: #1f1f1f; font-size: 17px; font-weight: 600; text-align: center; text-decoration: none; }
.google-btn:hover { background: #e8e8ea; }

@media (min-width: 701px) {
  .sb-title { font-size: 24px; }
}
@media (max-width: 700px) {
  .sidebar { width: 100%; border-right: 0; background: var(--bg); }
  .app.thread-open .sidebar { display: none; }
  .app:not(.thread-open) .thread { display: none; }
  .back-btn { display: grid; }
  .conv, .conv.active { margin: 0; padding: 0 16px 0 6px; border-radius: 0; background: none; }
  .conv.active .conv-body { border-bottom-color: var(--line); }
  .conv.active .conv-name { color: var(--fg); }
  .conv.active .conv-time, .conv.active .conv-last { color: var(--sub); }
  .conv.active .dot.on { background: var(--sent); }
}

/* typing indicator */
.bubble.typing { display: flex; gap: 4px; align-items: center; min-width: 58px; height: 36px; padding: 0 16px; }
.typing span { width: 8px; height: 8px; border-radius: 50%; background: var(--sub); animation: typing-pulse 1.2s infinite ease-in-out; }
.typing .dot-2 { animation-delay: 0.2s; }
.typing .dot-3 { animation-delay: 0.4s; }
@keyframes typing-pulse { 0%, 60%, 100% { opacity: 0.35; transform: scale(0.85); } 30% { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .typing span { animation: none; } }

/* profile pictures */
.av { position: relative; overflow: hidden; }
.av-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

/* avatar menu */
.menu-backdrop { position: fixed; inset: 0; z-index: 9; }
.menu { position: absolute; z-index: 10; top: calc(env(safe-area-inset-top) + 48px); left: 12px; min-width: 180px; padding: 4px; border-radius: 12px; background: #2c2c2e; box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55); border: 1px solid var(--line); }
.menu-item { display: block; box-sizing: border-box; color: inherit; text-decoration: none; width: 100%; padding: 10px 12px; border-radius: 8px; text-align: left; font-size: 16px; }
.menu-item:hover { background: var(--fill); }
.menu-item:last-child { color: var(--err); }

/* photo button and photo messages */
.attach { flex: none; width: 36px; height: 36px; margin-bottom: 1px; border-radius: 50%; display: grid; place-items: center; background: var(--fill); color: var(--sub); }
.attach:hover:not(:disabled) { color: var(--fg); }
.attach:disabled { opacity: 0.4; cursor: default; }
.bw { position: relative; z-index: 1; touch-action: pan-y; max-width: min(75%, 560px); }
/* a message with its reactions and menu open stacks over the later messages (each .bw is its own stacking context) */
.bw:has(.tapback) { z-index: 3; }
.bb { position: relative; }
.bw .bubble { max-width: none; }
/* touch: long-press opens the reaction bar and Copy is in it, so nothing outside the text fields is selectable (a long press near a bubble would otherwise select the whole page) */
@media (pointer: coarse) {
  body { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
  input, textarea { -webkit-user-select: text; user-select: text; }
  .bw .bubble { cursor: default; }
}
.bubble.photo { cursor: zoom-in; }
.bubble.photo { padding: 0; background: none; line-height: 0; }
.bubble.photo::before, .bubble.photo::after { display: none; }
.photo-img { display: block; max-width: min(260px, 100%); max-height: 340px; border-radius: 18px; background: var(--recv); }
video.photo-img { width: min(260px, 100%); height: auto; max-height: 340px; background: #000; object-fit: contain; }
.bubble.photo:has(video) { cursor: default; }
.upload-toast { position: fixed; top: calc(env(safe-area-inset-top) + 10px); left: 50%; transform: translateX(-50%); z-index: 50; padding: 8px 16px; border-radius: 18px; background: rgba(58, 58, 60, 0.95); color: var(--fg); font-size: 14px; pointer-events: none; }
@media (max-width: 700px) { .bw { max-width: 80%; } .photo-img { max-width: min(240px, 100%); } }

/* reactions */
.bb.has-rx { margin-top: 12px; }
.rx { position: absolute; z-index: 1; top: -12px; display: flex; gap: 2px; }
.sent .rx { left: -14px; }
.recv .rx { right: -14px; }
.rx-b { min-width: 26px; height: 26px; padding: 0 4px; border-radius: 13px; display: grid; place-items: center; font-size: 14px; line-height: 1; background: #3a3a3c; color: #fff; box-shadow: 0 0 0 2px var(--bg); }
.rx-b.mine { background: var(--sent); }
.rx-b.haha { font-size: 8px; font-weight: 800; letter-spacing: 0.02em; line-height: 0.95; width: 26px; padding: 0; text-align: center; }
.details { position: fixed; inset: 0; z-index: 15; background: var(--bg); overflow-y: auto; overscroll-behavior: contain; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
.details-done { position: absolute; right: 16px; top: calc(env(safe-area-inset-top) + 16px); font-size: 17px; font-weight: 600; color: var(--sent); }
.details-body { max-width: 520px; margin: 0 auto; padding: 56px 16px 24px; display: flex; flex-direction: column; align-items: center; }
.details-name { margin-top: 12px; font-size: 24px; font-weight: 600; text-align: center; overflow-wrap: anywhere; }
.details-mail { margin-top: 2px; color: var(--sub); font-size: 15px; overflow-wrap: anywhere; text-align: center; }
.details-nick { display: flex; gap: 8px; align-self: stretch; margin-top: 20px; }
.nick-input { flex: 1; min-width: 0; border: 0; outline: 0; border-radius: 10px; padding: 10px 12px; background: var(--fill); font-size: 17px; }
.nick-save { flex: none; color: var(--sent); font-size: 17px; padding: 0 8px; }
.details-h { align-self: flex-start; margin: 28px 0 8px 4px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--sub); }
.details-photos { align-self: stretch; display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
.details-photo { aspect-ratio: 1; overflow: hidden; border-radius: 4px; background: var(--recv); }
.details-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.details-none { align-self: flex-start; margin-left: 4px; color: var(--sub); }
.tb-scrim { position: fixed; inset: 0; z-index: 2; }
.lightbox { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(0, 0, 0, 0.92); cursor: zoom-out; }
.lightbox-img { max-width: 100vw; max-height: 100vh; object-fit: contain; }
.tapback { position: absolute; z-index: 3; bottom: calc(100% + 6px); display: flex; flex-wrap: wrap; width: max-content; max-width: calc(100vw - 24px); gap: 2px; padding: 4px; border-radius: 22px; background: #2c2c2e; box-shadow: 0 6px 22px rgba(0, 0, 0, 0.6); border: 1px solid var(--line); }
.sent .tapback { right: 0; }
.recv .tapback { left: 0; }
.tb-btn { width: 36px; height: 36px; border-radius: 50%; font-size: 20px; line-height: 1; display: grid; place-items: center; }
.tb-btn:hover { background: var(--fill); }
.older { display: flex; justify-content: center; padding: 8px 0 12px; cursor: pointer; }
.older-btn { padding: 6px 14px; border-radius: 16px; background: var(--fill); color: var(--sent); font-size: 14px; font-weight: 600; }
.actions { position: absolute; z-index: 3; top: calc(100% + 6px); width: 200px; max-width: calc(100vw - 24px); overflow: hidden; border-radius: 14px; background: #2c2c2e; box-shadow: 0 6px 22px rgba(0, 0, 0, 0.6); border: 1px solid var(--line); }
.actions.up { top: auto; bottom: calc(100% + 58px); }
.sent .actions { right: 0; }
.recv .actions { left: 0; }
.act { display: block; width: 100%; padding: 11px 16px; text-align: left; font-size: 17px; }
.act + .act { border-top: 1px solid var(--line); }
.act:hover { background: var(--fill); }
.act-danger { color: var(--err); }
.tb-btn.on { background: var(--sent); }
.tb-btn:last-child { font-size: 10px; font-weight: 800; }

/* replies: the dimmed quote above a reply, the bar over the composer, the swipe hint */
.quote { display: block; width: fit-content; max-width: 100%; margin-bottom: 3px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 16px; color: var(--sub); font-size: 14px; line-height: 1.25; overflow-wrap: anywhere; cursor: pointer; }
.quote-text { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; }
.sent .quote { margin-left: auto; }
/* mouse: a Reply button beside the hovered message (touch swipes instead) */
.reply-hover { display: none; }
@media (hover: hover) and (pointer: fine) {
  .reply-hover { display: grid; position: absolute; top: 50%; width: 34px; height: 28px; margin-top: -14px; place-items: center; border-radius: 14px; font-size: 18px; color: var(--sub); opacity: 0; }
  .sent .reply-hover { right: 100%; }
  .recv .reply-hover { left: 100%; }
  .bw:hover .reply-hover, .reply-hover:focus-visible { opacity: 1; }
  .reply-hover:hover { color: var(--fg); background: var(--fill); }
}
.reply-bar { flex: none; display: flex; align-items: center; gap: 8px; padding: 8px 12px 0 56px; background: var(--bg); }
.reply-card { flex: 1; min-width: 0; padding: 1px 10px; border-left: 3px solid var(--sent); }
.reply-to { font-size: 12px; font-weight: 600; color: var(--sub); }
.reply-snip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; color: var(--sub); }
.reply-x { flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--fill); color: var(--sub); }
.m { position: relative; }
.m.swiping::after { content: "\21A9"; position: absolute; top: 50%; transform: translateY(-50%); width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--fill); color: var(--sub); font-size: 16px; opacity: 0.5; }
.m.swiping.armed::after { background: var(--sent); color: #fff; opacity: 1; }
.recv.swiping::after { left: 0; }
.sent.swiping::after { right: 0; }
