/* Colors follow WhatsApp's palette, darkened where needed to reach 4.5:1 text contrast. */
:root {
  color-scheme: light dark;
  --bar: #008069;
  --on-bar: #ffffff;
  --bg: #f0f2f5;
  --wallpaper: #efeae2;
  --panel: #ffffff;
  --text: #111b21;
  --text-2: #54656f;
  --sep: #e9edef;
  --accent: #007060;
  --on-accent: #ffffff;
  --bubble: #d9fdd3;
  --bubble-meta: #54656f;
  --doc: rgba(11, 20, 26, 0.06);
  --avatar: #dfe5e7;
  --on-avatar: #3b4a54;
  --danger: #d1242f;
  --on-danger: #ffffff;
  --field: #ffffff;
  --field-line: #d1d7db;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bar: #202c33;
    --on-bar: #e9edef;
    --bg: #111b21;
    --wallpaper: #0b141a;
    --panel: #111b21;
    --text: #e9edef;
    --text-2: #8696a0;
    --sep: #222d34;
    --accent: #00a884;
    --on-accent: #111b21;
    --bubble: #005c4b;
    --bubble-meta: #c2ded7;
    --doc: rgba(0, 0, 0, 0.2);
    --avatar: #3b4a54;
    --on-avatar: #e9edef;
    --danger: #ff8591;
    --on-danger: #111b21;
    --field: #202c33;
    --field-line: #3b4a54;
  }
}

/* 17px body by default; on iOS the size follows the system text-size setting. */
html { font-size: 106.25%; -webkit-text-size-adjust: 100%; }
@supports (font: -apple-system-body) { html { font: -apple-system-body; } }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.4;
}

a { color: var(--accent); text-underline-offset: 0.15em; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.bar {
  background: var(--bar);
  color: var(--on-bar);
  padding: calc(env(safe-area-inset-top) + 0.75rem) calc(env(safe-area-inset-right) + 1rem) 0.75rem calc(env(safe-area-inset-left) + 1rem);
}
.bar h1 { margin: 0 auto; max-width: 36rem; font-size: 1.2rem; font-weight: 600; }

.chat-head { display: flex; align-items: center; gap: 0.75rem; max-width: 36rem; margin: 0 auto; }
.chat-head .who { display: flex; flex-direction: column; }
.chat-head .name { font-size: 1.1rem; font-weight: 600; }
.chat-head .sub { font-size: 0.85rem; opacity: 0.85; }

main {
  max-width: 36rem;
  margin: 0 auto;
  padding: 1rem calc(env(safe-area-inset-right) + 1rem) calc(env(safe-area-inset-bottom) + 2rem) calc(env(safe-area-inset-left) + 1rem);
}

.lead { color: var(--text-2); margin: 0.25rem 0 1.25rem; }
.note { color: var(--text-2); font-size: 0.875rem; }
.error { color: var(--danger); font-weight: 600; margin: 0 0 1rem; }

h2 { font-size: 0.9375rem; font-weight: 600; color: var(--accent); margin: 1.75rem 0 0.5rem; }

/* Forms */

label { display: block; font-size: 0.9375rem; color: var(--text-2); margin-bottom: 1rem; }
label .hint { display: block; font-size: 0.8125rem; margin-top: 0.25rem; }
input[type=text], input[type=password], input[type=tel], input[type=search] {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  min-height: 2.9rem;
  padding: 0.6rem 0.9rem;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--field-line);
  border-radius: 0.75rem;
}
input:focus { border-color: var(--accent); }

/* Buttons: pill-shaped like WhatsApp's, full width in forms */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.9rem;
  padding: 0.6rem 1.4rem;
  font: inherit;
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
}
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.block { display: flex; width: 100%; margin-top: 0.75rem; }
.btn:active { filter: brightness(0.92); }
.link-button {
  min-height: 2.75rem;
  padding: 0 0.5rem;
  font: inherit;
  font-weight: 600;
  background: none;
  border: 0;
  color: var(--accent);
  cursor: pointer;
}
.link-button.danger { color: var(--danger); }
.link-button.center { display: block; margin: 1rem auto 0; text-align: center; text-decoration: none; }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.primary.danger { background: var(--danger); color: var(--on-danger); }
.row .actions { display: flex; flex-wrap: wrap; gap: 0 0.25rem; margin-left: -0.5rem; }
.invite-code { font-size: 1.6rem; font-weight: 700; letter-spacing: 0.08em; text-align: center; margin: 0.5rem 0 1rem; }
textarea { display: block; width: 100%; margin-top: 0.35rem; padding: 0.6rem 0.9rem; font: inherit; font-size: 0.9375rem;
  color: var(--text); background: var(--field); border: 1px solid var(--field-line); border-radius: 0.75rem; resize: vertical; }
form.inline { display: inline; margin: 0; }

/* Chat-list rows, laid out like WhatsApp's */

.list { background: var(--panel); border-radius: 0.75rem; overflow: hidden; }
.row { display: flex; align-items: center; gap: 0.85rem; padding-left: 0.9rem; }
.row .body { flex: 1; min-width: 0; display: flex; align-items: center; gap: 0.5rem; min-height: 4.25rem; padding: 0.6rem 0.9rem 0.6rem 0; }
.row + .row .body { border-top: 1px solid var(--sep); }
.row .main { flex: 1; min-width: 0; }
.row .top { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
.row .title { font-weight: 600; overflow-wrap: anywhere; }
.row .time { flex-shrink: 0; font-size: 0.8125rem; color: var(--text-2); }
.row .sub {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--text-2);
  font-size: 0.875rem;
  overflow-wrap: anywhere;
}
.empty { margin: 0; padding: 1rem 0.9rem; color: var(--text-2); }
form.search { margin-top: 1.25rem; }

.avatar {
  flex-shrink: 0;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--avatar);
  color: var(--on-avatar);
  font-weight: 600;
}
.bar .avatar { background: rgba(255, 255, 255, 0.25); color: var(--on-bar); }

/* The held message, drawn as an outgoing WhatsApp bubble */

.wallpaper { background: var(--wallpaper); padding: 1.5rem 1rem; border-radius: 0.75rem; display: flex; justify-content: flex-end; }
.bubble {
  position: relative;
  max-width: 85%;
  background: var(--bubble);
  color: var(--text);
  padding: 0.45rem 0.6rem 0.35rem 0.7rem;
  border-radius: 0.6rem 0 0.6rem 0.6rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.bubble::after {
  content: "";
  position: absolute;
  top: 0;
  right: -0.5rem;
  border-top: 0.6rem solid var(--bubble);
  border-right: 0.5rem solid transparent;
}
.bubble .meta { display: flex; justify-content: flex-end; align-items: center; gap: 0.25rem; margin-top: 0.15rem; font-size: 0.75rem; color: var(--bubble-meta); white-space: nowrap; }
.bubble .meta svg { width: 1rem; height: 1rem; }

/* Held files: WhatsApp's document card inside the bubble; later bubbles in a run lose the tail */
.wallpaper.stack { flex-direction: column; align-items: flex-end; gap: 0.3rem; }
.stack .bubble + .bubble { border-radius: 0.6rem; }
.stack .bubble + .bubble::after { display: none; }
.bubble.file { white-space: normal; width: min(18rem, 85%); }
.bubble .preview { display: block; width: 100%; max-height: 20rem; object-fit: cover; border-radius: 0.45rem; margin-bottom: 0.35rem; }
.bubble .doc { display: flex; align-items: center; gap: 0.6rem; padding: 0.6rem; border-radius: 0.45rem; background: var(--doc); color: inherit; text-decoration: none; }
.bubble .doc svg { flex: none; width: 2rem; height: 2.5rem; color: var(--bubble-meta); }
.bubble .doc-text { display: flex; flex-direction: column; min-width: 0; }
.bubble .doc-name { font-weight: 600; overflow-wrap: anywhere; }
.bubble .doc-meta { font-size: 0.8125rem; color: var(--bubble-meta); }
.bubble .caption { display: block; margin-top: 0.4rem; white-space: pre-wrap; }

/* Linking */

ol.steps { padding-left: 1.4rem; margin: 0 0 1.25rem; }
ol.steps li { margin-bottom: 0.4rem; }
.qr { display: block; width: 16.5rem; max-width: 100%; aspect-ratio: 1; margin: 0 auto 1rem; padding: 0.75rem; background: #ffffff; border-radius: 0.75rem; }
.status { text-align: center; color: var(--text-2); font-size: 0.9375rem; }
.code { display: flex; justify-content: center; gap: 0.35rem; margin: 1rem 0 1.25rem; }
.code .cell {
  width: 2.3rem;
  height: 2.9rem;
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  font-weight: 700;
  background: var(--panel);
  border: 1px solid var(--field-line);
  border-radius: 0.5rem;
}
.code .gap { width: 0.6rem; }
.card { background: var(--panel); border-radius: 0.75rem; padding: 1rem; margin-top: 1.25rem; }

@media (min-width: 40rem) {
  main { padding-top: 2rem; }
}
