/* BuilderX chat: Messages on an iPhone, in plain CSS. Light and dark follow the system. */

:root {
  --bg: #ffffff;
  --bar: rgba(247, 247, 247, 0.9);
  --bar-line: rgba(0, 0, 0, 0.14);
  --text: #000000;
  --muted: #8e8e93;
  --blue: #007aff;
  --grey: #e9e9eb;
  --grey-text: #000000;
  --field-bg: #ffffff;
  --field-line: #c7c7cc;
  --send-off: #d1d1d6;
  --online: #34c759;
  --offline: #aeaeb2;
  --red: #ff3b30;
  --page: #f2f2f7;
  --panel-line: rgba(0, 0, 0, 0.08);
  --group-bg: #f2f2f7;
  --sep-text: #8e8e93;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bar: rgba(22, 22, 24, 0.86);
    --bar-line: rgba(255, 255, 255, 0.14);
    --text: #ffffff;
    --muted: #8e8e93;
    --blue: #0a84ff;
    --grey: #26252a;
    --grey-text: #ffffff;
    --field-bg: #000000;
    --field-line: #3a3a3c;
    --send-off: #3a3a3c;
    --online: #30d158;
    --offline: #636366;
    --red: #ff453a;
    --page: #000000;
    --panel-line: rgba(255, 255, 255, 0.1);
    --group-bg: #1c1c1e;
    --sep-text: #8e8e93;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--page);
  color: var(--text);
  font: 16px/1.3 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

button, input, textarea { font: inherit; color: inherit; margin: 0; }

.screen {
  position: fixed;
  inset: 0;
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* On a wide screen the conversation is a column in the middle, as in Messages on a Mac. */
@media (min-width: 900px) {
  .chat-screen {
    width: min(100%, 760px);
    left: 50%;
    transform: translateX(-50%);
    border-left: 1px solid var(--panel-line);
    border-right: 1px solid var(--panel-line);
  }
}

/* ---------------------------------------------------------------- login */

.login-screen { background: var(--page); justify-content: center; align-items: center; padding: 24px; }
.login {
  width: min(100%, 320px);
  display: flex; flex-direction: column; align-items: stretch; gap: 12px;
  padding-bottom: env(safe-area-inset-bottom);
}
.app-icon {
  width: 84px; height: 84px; margin: 0 auto 6px; border-radius: 20px;
  background: linear-gradient(180deg, #5df777 0%, #21c542 100%);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  display: flex; align-items: center; justify-content: center;
}
.app-icon span {
  position: relative; width: 52px; height: 40px; background: #fff; border-radius: 20px;
}
.app-icon span::after {
  content: ""; position: absolute; left: 8px; bottom: -6px; width: 14px; height: 14px; background: #fff;
  border-radius: 0 0 14px 2px; transform: skewX(20deg);
}
.login h1 { margin: 0; font-size: 26px; font-weight: 700; text-align: center; letter-spacing: -0.2px; }
.login .sub { margin: -6px 0 6px; text-align: center; color: var(--muted); font-size: 15px; }
.login input {
  width: 100%; height: 50px; padding: 0 16px; border: 0; outline: none; border-radius: 12px;
  background: var(--bg); color: var(--text); font-size: 17px;
  box-shadow: 0 0 0 1px var(--panel-line);
}
.login input:focus { box-shadow: 0 0 0 2px var(--blue); }
.login input::placeholder { color: var(--muted); }
button.primary {
  height: 50px; border: 0; border-radius: 12px; background: var(--blue); color: #fff;
  font-size: 17px; font-weight: 600; cursor: pointer;
}
button.primary:active { filter: brightness(0.92); }
button.primary:disabled { opacity: 0.5; cursor: default; }
.error { color: var(--red); font-size: 14px; margin: 0; text-align: center; }

/* ------------------------------------------------------------------ bar */

.bar {
  position: relative; z-index: 2;
  display: flex; align-items: center;
  padding: 6px 8px 8px;
  padding-top: calc(6px + env(safe-area-inset-top));
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  box-shadow: 0 0.5px 0 var(--bar-line);
}
.bar-side { flex: 1; display: flex; }
.bar-side.right { justify-content: flex-end; }
.who { display: flex; flex-direction: column; align-items: center; min-width: 0; line-height: 1.2; }
.name { display: flex; align-items: center; gap: 6px; font-size: 16px; font-weight: 600; letter-spacing: -0.2px; }
.presence { font-size: 11px; color: var(--muted); min-height: 13px; }
.presence.typing { color: var(--blue); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--offline); transition: background 0.3s; }
.dot.online { background: var(--online); box-shadow: 0 0 0 2px rgba(52, 199, 89, 0.22); }
button.link {
  background: none; border: 0; padding: 8px 8px; color: var(--blue); font-size: 15px; cursor: pointer; border-radius: 8px;
}
button.link:active { opacity: 0.5; }

/* --------------------------------------------------------------- thread */

.thread-wrap { position: relative; flex: 1; min-height: 0; display: flex; }
.thread {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden;
  padding: 12px 0 8px;
  display: flex; flex-direction: column;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.thread > :first-child { margin-top: auto; }

.empty { color: var(--muted); text-align: center; font-size: 14px; margin: 24px 24px; }

.sep {
  text-align: center; font-size: 11px; color: var(--sep-text); margin: 14px 12px 4px; letter-spacing: 0.1px;
}
.sep b { font-weight: 600; }
.sep:first-child { margin-top: auto; padding-top: 4px; }

.row {
  display: flex; padding: 0 12px; margin-top: 2px;
  transform-origin: bottom left;
}
.row.you { justify-content: flex-end; transform-origin: bottom right; }
.row.first { margin-top: 10px; }
.sep + .row { margin-top: 4px; }

.bubble {
  position: relative;
  max-width: min(76%, 520px);
  padding: 7px 13px 8px;
  border-radius: 18px;
  font-size: 17px; line-height: 1.28;
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word;
  cursor: default;
  -webkit-user-select: text; user-select: text;
}
.row.main .bubble { background: var(--grey); color: var(--grey-text); }
.row.you .bubble { background: var(--blue); color: #fff; }
.row.you.pending .bubble { opacity: 0.72; }
.row.you.failed .bubble { background: var(--red); }
.bubble a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

/* The tail on the last bubble of a group: a filled corner and a cut in the page colour. */
.row.tail .bubble::before, .row.tail .bubble::after { content: ""; position: absolute; bottom: 0; height: 20px; }
.row.main.tail .bubble::before { left: -7px; width: 20px; background: var(--grey); border-bottom-right-radius: 16px 14px; }
.row.main.tail .bubble::after { left: -10px; width: 10px; background: var(--bg); border-bottom-right-radius: 10px; }
.row.you.tail .bubble::before { right: -7px; width: 20px; background: var(--blue); border-bottom-left-radius: 16px 14px; }
.row.you.failed.tail .bubble::before { background: var(--red); }
.row.you.tail .bubble::after { right: -10px; width: 10px; background: var(--bg); border-bottom-left-radius: 10px; }

.row.new { animation: pop 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2); }
@keyframes pop {
  from { opacity: 0; transform: translateY(8px) scale(0.92); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) { .row.new { animation: none; } }

.stamp, .caption {
  font-size: 11px; color: var(--muted); padding: 2px 16px 0; line-height: 1.3;
}
.stamp.you, .caption { text-align: right; }
.caption { font-weight: 500; }
.caption.failed { color: var(--red); }

/* Typing: three dots that rise and fall in turn. */
.dots { display: inline-flex; gap: 5px; align-items: center; height: 22px; padding: 0 2px; }
.dots i {
  width: 8px; height: 8px; border-radius: 50%; background: var(--muted); opacity: 0.6;
  animation: bob 1.2s infinite ease-in-out;
}
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bob {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.pill {
  position: absolute; left: 50%; bottom: 12px; transform: translate(-50%, 0);
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border: 0; border-radius: 999px;
  background: var(--blue); color: #fff; font-size: 13px; font-weight: 600;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
  cursor: pointer;
  animation: rise 0.2s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* -------------------------------------------------------------- compose */

.compose {
  position: relative; z-index: 2;
  padding: 6px 10px;
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  box-shadow: 0 -0.5px 0 var(--bar-line);
}
.field {
  display: flex; align-items: flex-end; gap: 6px;
  min-height: 36px; padding: 2px 3px 2px 14px;
  border: 1px solid var(--field-line); border-radius: 20px; background: var(--field-bg);
}
.field:focus-within { border-color: var(--field-line); }
.compose textarea {
  flex: 1; min-width: 0; border: 0; outline: none; background: none; resize: none;
  padding: 6px 0 6px; line-height: 20px; font-size: 17px; max-height: 112px; overflow-y: hidden;
  color: var(--text);
}
.compose textarea::placeholder { color: var(--muted); }
#send {
  flex: none; width: 30px; height: 30px; margin: 1px 0; padding: 0; border: 0; border-radius: 50%;
  background: var(--blue); color: #fff; display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background 0.15s, transform 0.15s;
}
#send:disabled { background: var(--send-off); cursor: default; }
#send:not(:disabled):active { transform: scale(0.92); }

.toast {
  position: absolute; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 3; max-width: 90%;
  background: var(--grey); color: var(--grey-text); border-radius: 12px; padding: 8px 14px; font-size: 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
}

@media (min-width: 600px) {
  .bubble { font-size: 15px; padding: 7px 12px 8px; }
  .compose textarea { font-size: 15px; }
  .stamp, .caption, .sep { font-size: 11px; }
}
