/* ============================================================================
   ComplyChat — Governed Rooms PWA
   Red-skinned WhatsApp-mimic. Brand colour = RED (never WhatsApp green/teal).
   Own artwork only: the wallpaper is our own CSS/SVG doodle pattern in muted
   tones; icons are our own SVG glyphs. British English throughout.
   ========================================================================== */

:root {
  --red:        #b3261e;   /* primary brand red */
  --red-dark:   #8c1d17;
  --red-tint:   #fde7e5;   /* outgoing bubble tint (light red/pink) */
  --ink:        #1c1b1f;
  --ink-soft:   #5b5960;
  --line:       #e3e1e6;
  --bg-app:     #f4f2f5;
  --bg-bubble-in: #ffffff;
  --tick-grey:  #8b9aa6;
  --unread-red: var(--red);
  --wallpaper-base: #ece5dc;        /* muted warm neutral */
  --wallpaper-wash: rgba(236, 229, 220, .7); /* translucent wash over the doodle tile, keeps bubbles legible */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --topbar-h: 56px;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.12);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

.app {
  height: 100%;
  max-width: 560px;          /* phone-width app, centred on desktop */
  margin: 0 auto;
  position: relative;
  background: var(--bg-app);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* The hidden attribute MUST win over the display rules below — view switching
   (#view-landing/otp/rooms/room) and the coachmark all rely on [hidden] to hide. */
[hidden] { display: none !important; }

.view {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ── Recording-dot motif ──────────────────────────────────────────────────── */
.rec-dot {
  display: inline-block;
  flex: 0 0 auto; /* never let a flex row (brand / topbar / auth-note) squash the dot into an oval */
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(179, 38, 30, .18);
  animation: rec-pulse 2s ease-in-out infinite;
}
.rec-dot--sm { width: 9px; height: 9px; box-shadow: 0 0 0 3px rgba(179, 38, 30, .18); }
@keyframes rec-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .45; }
}
@media (prefers-reduced-motion: reduce) {
  .rec-dot { animation: none; }
}

/* ============================================================================
   Auth views (landing + OTP)
   ========================================================================== */
.view--auth {
  justify-content: center;
  align-items: center;
  padding: 24px 18px calc(24px + var(--safe-bottom));
  background:
    radial-gradient(120% 80% at 50% -10%, #fff 0%, var(--bg-app) 60%);
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 26px 22px;
  box-shadow: 0 6px 24px rgba(0,0,0,.06);
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 18px;
}
.brand-name { font-weight: 700; letter-spacing: .2px; }
.auth-title { font-size: 1.4rem; margin: 0 0 4px; }
.auth-purpose { color: var(--red-dark); font-weight: 600; margin: 0 0 8px; min-height: 0; }
.auth-purpose:empty { display: none; }
.auth-sub { color: var(--ink-soft); font-size: .95rem; margin: 0 0 18px; }
.auth-form { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: .8rem; font-weight: 600; color: var(--ink-soft); }
.field {
  font-size: 1.05rem;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  transition: border-color .15s;
}
.field:focus { border-color: var(--red); }
.field--otp {
  letter-spacing: .5em;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: 1.4rem;
}
.field-error {
  color: var(--red-dark);
  font-size: .85rem;
  margin: 2px 0 0;
}
.otp-phone { font-weight: 600; color: var(--ink); }
.auth-note {
  margin: 18px 0 0;
  font-size: .8rem;
  color: var(--ink-soft);
  display: flex;
  align-items: baseline;
  gap: 7px;
  line-height: 1.4;
}

.btn {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
}
.btn--primary {
  background: var(--red);
  color: #fff;
  font-weight: 600;
  padding: 13px 16px;
  margin-top: 8px;
}
.btn--primary:hover { background: var(--red-dark); }
.btn--primary:disabled { opacity: .6; cursor: progress; }
.btn--link {
  background: none;
  color: var(--ink-soft);
  padding: 8px;
  text-decoration: underline;
}

/* ============================================================================
   App chrome (chats-list + conversation)
   ========================================================================== */
.topbar {
  flex: 0 0 auto;
  min-height: var(--topbar-h);
  padding-top: var(--safe-top);
  background: var(--red);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 14px;
  padding-right: 14px;
  box-shadow: var(--shadow);
  z-index: 5;
}
.topbar-title {
  font-size: 1.1rem;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
}
.topbar-title .rec-dot { background: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.3); }
.topbar-action {
  font: inherit;
  background: rgba(255,255,255,.18);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
}
.topbar-action:hover { background: rgba(255,255,255,.3); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
}

/* ── Chats-list ───────────────────────────────────────────────────────────── */
.rooms-list {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: #fff;
}
.room-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
  text-align: left;
  width: 100%;
  background: #fff;
  border-left: none;
  border-right: none;
  border-top: none;
  font: inherit;
  color: inherit;
}
.room-row:hover { background: #faf8f9; }
.room-row:active { background: #f1eef0; }

.avatar {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  font-size: 1.05rem;
  user-select: none;
}
.room-meta {
  flex: 1 1 auto;
  min-width: 0;
}
.room-name {
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.room-preview {
  color: var(--ink-soft);
  font-size: .88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.room-side {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
}
.room-time { font-size: .72rem; color: var(--ink-soft); }
.unread-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--unread-red);
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.room-time.has-unread { color: var(--unread-red); font-weight: 600; }

.rooms-empty {
  padding: 40px 24px;
  text-align: center;
  color: var(--ink-soft);
}

/* ── Conversation view ────────────────────────────────────────────────────── */
.topbar--room { padding-left: 4px; }
.room-avatar {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  background: var(--red-dark);
  font-size: .9rem;
}
.room-head { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
.room-title {
  font-size: 1.02rem;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.room-sub { font-size: .74rem; opacity: .85; }

/* Wallpaper — doodle art (wallpaper-pattern.png, recoloured onto our beige),
   shown once as a full-bleed backdrop (not tiled — the source art has no
   clean repeat unit, so tiling it left visible seams). A translucent wash of
   the same beige sits over it so bubbles/text stay legible against the line art. */
.msg-wallpaper {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  position: relative;
  background-color: var(--wallpaper-base);
  background-image:
    linear-gradient(var(--wallpaper-wash), var(--wallpaper-wash)),
    url("wallpaper-pattern.png");
  background-repeat: no-repeat;
  background-size: cover, cover;
  background-position: center, center;
}
.msg-list {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 10px calc(12px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Date separator + system line (centred pills) */
.day-sep, .system-line {
  align-self: center;
  background: rgba(255,255,255,.92);
  color: var(--ink-soft);
  font-size: .74rem;
  padding: 4px 12px;
  border-radius: 14px;
  margin: 8px 0;
  box-shadow: var(--shadow);
  text-align: center;
  max-width: 86%;
}
.system-line {
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(255, 240, 239, .95);
  color: var(--red-dark);
}

/* Bubbles — incoming white/light on the left; outgoing light-red tint on the
   right; little tail on the top corner (mirrors WhatsApp structure). */
.msg {
  max-width: 80%;
  padding: 7px 10px 6px;
  border-radius: 8px;
  position: relative;
  font-size: .95rem;
  line-height: 1.35;
  box-shadow: var(--shadow);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg--in {
  align-self: flex-start;
  background: var(--bg-bubble-in);
  border-top-left-radius: 2px;
}
.msg--out {
  align-self: flex-end;
  background: var(--red-tint);
  border-top-right-radius: 2px;
}
/* tails */
.msg--in::before,
.msg--out::before {
  content: "";
  position: absolute;
  top: 0;
  width: 0;
  height: 0;
  border: 7px solid transparent;
}
.msg--in::before {
  left: -7px;
  border-top-color: var(--bg-bubble-in);
  border-right-color: var(--bg-bubble-in);
}
.msg--out::before {
  right: -7px;
  border-top-color: var(--red-tint);
  border-left-color: var(--red-tint);
}

.msg-sender {
  font-size: .76rem;
  font-weight: 700;
  margin-bottom: 1px;
  color: var(--red-dark);
}
.msg-text { white-space: pre-wrap; }
.msg-img {
  display: block;
  max-width: 100%;
  border-radius: 8px;
  margin-bottom: 3px;
}
.msg-img--missing {
  font-size: .82rem;
  color: var(--ink-soft);
  font-style: italic;
}
.msg-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 2px;
  font-size: .68rem;
  color: var(--ink-soft);
}

/* Tick glyphs (our own). One grey = sent; two grey = delivered; two RED = read. */
.ticks {
  display: inline-flex;
  align-items: center;
  line-height: 1;
}
.ticks svg { display: block; }
.ticks--sent      { color: var(--tick-grey); }
.ticks--delivered { color: var(--tick-grey); }
.ticks--read      { color: var(--red); }

/* ── Typing indicator (GR-B3) — a slim ephemeral line above the composer ───── */
.typing-indicator {
  flex: 0 0 auto;
  padding: 4px 14px;
  font-size: .8rem;
  font-style: italic;
  color: var(--ink-soft);
  background: var(--bg-app);
  min-height: 22px;
  line-height: 1.4;
}

/* ── Composer ─────────────────────────────────────────────────────────────── */
.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px calc(8px + var(--safe-bottom));
  background: var(--bg-app);
  border-top: 1px solid var(--line);
}
/* Pill field holds the text input + inline icon(s), mirroring WhatsApp's
   compose field; the send button floats outside it as its own round FAB. */
.composer-field {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 22px;
}
.composer-field:focus-within { border-color: var(--red); }
.icon-btn--composer { color: var(--ink-soft); margin-right: 2px; }
.icon-btn--composer:disabled { opacity: .55; cursor: default; }
.composer-input {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 1rem;
  padding: 11px 6px 11px 14px;
  border: none;
  outline: none;
  background: transparent;
}
.icon-btn--send {
  background: var(--red);
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.icon-btn--send:hover { background: var(--red-dark); }
.icon-btn--send:disabled { opacity: .5; cursor: default; box-shadow: none; }

/* ============================================================================
   Coachmark + toast
   ========================================================================== */
.coachmark {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 0 12px calc(20px + var(--safe-bottom));
}
.coachmark-card {
  background: #fff;
  border-radius: 16px;
  padding: 20px 18px;
  max-width: 420px;
  width: 100%;
  position: relative;
  box-shadow: 0 -4px 24px rgba(0,0,0,.2);
}
.coachmark-title { margin: 0 0 8px; font-size: 1.1rem; color: var(--red-dark); }
.coachmark-card p { margin: 0; color: var(--ink-soft); font-size: .92rem; line-height: 1.45; }
.coachmark-close {
  position: absolute;
  top: 8px; right: 10px;
  background: none; border: none;
  font-size: 1.6rem; line-height: 1;
  color: var(--ink-soft); cursor: pointer;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(76px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 22px;
  font-size: .88rem;
  z-index: 60;
  max-width: 90%;
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
}

/* spinner / empty hint inside lists */
.loading {
  padding: 30px;
  text-align: center;
  color: var(--ink-soft);
  font-size: .9rem;
}
