/* WhatsApp assistant demo.
 *
 * Two halves: a phone that looks like WhatsApp, and an inspector that shows the
 * lookup and the rule behind each reply. The inspector is the point — a chat
 * bubble proves nothing on its own, and the question a buyer actually has is
 * "where did that number come from, and what happens when it doesn't know".
 */

:root {
  --ink: #12151c;
  --muted: #5b6472;
  --line: #e2e6ec;
  --bg: #f4f6f8;
  --card: #ffffff;
  --wa-green: #25d366;
  --wa-teal: #075e54;
  --wa-bubble-in: #ffffff;
  --wa-bubble-out: #d9fdd3;
  --wa-paper: #efe7de;
  --accent: #3b3ff2;
  --grad: linear-gradient(120deg, #0568dc 0%, #6127f6 100%);
  --font-body: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Inter, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ------------------------------------------------------------------ top -- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brandline { display: flex; align-items: center; gap: 12px; }
.mark {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  border-radius: 9px;
  background: #0d2242; color: #fff;
  font-weight: 700; font-size: 17px;
}
.topbar h1 { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
/* :where() holds this at (0,1,0). As a plain `.topbar p` it is (0,1,1) and beats
 * the one-class `.disclaimer` rule below regardless of order — which is exactly
 * what happened: the disclaimer's right margin was silently discarded and the
 * pill ran underneath the language switch. */
.topbar :where(p) { margin: 1px 0 0; font-size: 12.5px; color: var(--muted); }
.disclaimer {
  margin: 0;
  font-size: 11.5px;
  color: var(--muted);
  padding: 5px 10px;
  border: 1px dashed var(--line);
  border-radius: 999px;
  /* Clears the fixed language switch, which is 12px from the right edge and
   * about 66px wide. Measured rather than guessed: at 84px the pill still ran
   * under the control on a 1280 viewport. */
  margin-right: 96px;
}

/* ---------------------------------------------------------------- stage -- */
.stage {
  display: grid;
  grid-template-columns: minmax(320px, 400px) minmax(300px, 1fr);
  gap: 28px;
  align-items: start;
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 24px 56px;
}

/* ---------------------------------------------------------------- phone -- */
.phone-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.phone {
  width: 100%;
  max-width: 380px;
  border-radius: 34px;
  padding: 10px;
  background: #1b1f27;
  box-shadow: 0 20px 50px rgba(18, 21, 28, 0.22), 0 2px 6px rgba(18, 21, 28, 0.14);
}
.phone-screen {
  display: flex;
  flex-direction: column;
  height: 620px;
  border-radius: 25px;
  overflow: hidden;
  background: var(--wa-paper);
}

.wa-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 12px 11px;
  background: var(--wa-teal);
  color: #fff;
  flex: none;
}
.wa-back { display: none; }
.wa-avatar {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  background: #0d2242; color: #fff;
  font-weight: 700; font-size: 15px;
}
.wa-who { min-width: 0; }
.wa-who strong {
  display: flex; align-items: center; gap: 5px;
  font-size: 14.5px; font-weight: 600;
}
.verified { width: 14px; height: 14px; flex: none; }
.wa-status { display: block; font-size: 11.5px; opacity: 0.82; }

.wa-log {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 6px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  /* The faint doodle field WhatsApp uses, drawn rather than fetched. */
  background-color: var(--wa-paper);
  background-image:
    radial-gradient(circle at 12% 20%, rgba(0, 0, 0, 0.035) 1.2px, transparent 1.2px),
    radial-gradient(circle at 63% 71%, rgba(0, 0, 0, 0.03) 1.4px, transparent 1.4px),
    radial-gradient(circle at 87% 34%, rgba(0, 0, 0, 0.028) 1px, transparent 1px);
  background-size: 78px 78px, 104px 104px, 61px 61px;
  scroll-behavior: smooth;
}

.msg {
  max-width: 82%;
  padding: 6px 9px 5px;
  border-radius: 8px;
  font-size: 13.6px;
  line-height: 1.42;
  position: relative;
  box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: pop 0.18s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) { .msg { animation: none; } }

.msg.in  { align-self: flex-start; background: var(--wa-bubble-in); border-top-left-radius: 2px; }
.msg.out { align-self: flex-end;  background: var(--wa-bubble-out); border-top-right-radius: 2px; }
.msg .meta {
  display: block;
  text-align: right;
  font-size: 10.5px;
  color: #667781;
  margin-top: 1px;
  line-height: 1;
}
.msg .meta .ticks { color: #53bdeb; letter-spacing: -2px; margin-left: 3px; }

.msg .doc {
  display: flex; align-items: center; gap: 8px;
  margin: 2px 0 5px;
  padding: 8px 9px;
  border-radius: 6px;
  background: rgba(11, 20, 26, 0.055);
  font-size: 12.5px;
}
.msg .doc b { font-weight: 600; }
.msg .doc span { color: #667781; font-size: 11px; display: block; }

.typing {
  align-self: flex-start;
  display: inline-flex; gap: 3px; align-items: center;
  padding: 10px 12px;
  border-radius: 8px;
  border-top-left-radius: 2px;
  background: var(--wa-bubble-in);
  box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
}
.typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: #9aa6ad;
  animation: blink 1.15s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: 0.18s; }
.typing i:nth-child(3) { animation-delay: 0.36s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.35; } 30% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing i { animation: none; opacity: 0.6; } }

.wa-chips {
  flex: none;
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 8px 12px 4px;
  background: var(--wa-paper);
}
.wa-chips:empty { padding: 0; }
.wa-chips button {
  appearance: none;
  border: 1px solid rgba(7, 94, 84, 0.35);
  background: #fff;
  color: var(--wa-teal);
  font: 600 12.5px/1 var(--font-body);
  padding: 8px 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.12s ease;
}
.wa-chips button:hover { background: #eafaf1; }
.wa-chips button:active { transform: translateY(1px); }
.wa-chips button:focus-visible { outline: 2px solid var(--wa-green); outline-offset: 2px; }

.wa-compose {
  flex: none;
  display: flex; gap: 7px; align-items: center;
  padding: 8px 10px 10px;
  background: var(--wa-paper);
}
.wa-compose input {
  flex: 1; min-width: 0;
  border: 0; border-radius: 999px;
  padding: 10px 14px;
  font: 400 13.6px/1.2 var(--font-body);
  background: #fff;
  color: var(--ink);
}
.wa-compose input:focus-visible { outline: 2px solid var(--wa-green); outline-offset: 1px; }
.wa-compose button {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: var(--wa-green); color: #fff;
  cursor: pointer;
}
.wa-compose button svg { width: 19px; height: 19px; }
.wa-compose button:focus-visible { outline: 2px solid var(--wa-teal); outline-offset: 2px; }

.phone-actions { display: flex; gap: 8px; }
.ghost {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  font: 600 12px/1 var(--font-body);
  padding: 8px 13px;
  border-radius: 8px;
  cursor: pointer;
}
.ghost:hover { color: var(--ink); border-color: #c9ced8; }

/* ------------------------------------------------------------ inspector -- */
.inspector {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px 22px 24px;
  position: sticky;
  top: 24px;
}
.inspector h2 { margin: 0 0 6px; font-size: 14px; font-weight: 650; letter-spacing: -0.01em; }
.inspector > header p { margin: 0 0 16px; font-size: 12.8px; color: var(--muted); max-width: 46ch; }

.trace { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.trace li {
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 9px;
  padding: 11px 13px;
  background: #fbfcfd;
  animation: slidein 0.22s ease-out;
}
@keyframes slidein { from { opacity: 0; transform: translateX(-6px); } }
@media (prefers-reduced-motion: reduce) { .trace li { animation: none; } }
.trace li[data-kind="escalate"] { border-left-color: #e0812b; }
.trace li[data-kind="unknown"]  { border-left-color: #b4321f; }

.trace .step {
  font: 600 10px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--accent);
  display: block;
  margin-bottom: 5px;
}
.trace li[data-kind="escalate"] .step { color: #b3620f; }
.trace li[data-kind="unknown"] .step  { color: #b4321f; }
.trace h3 { margin: 0 0 4px; font-size: 13px; font-weight: 600; }
.trace p { margin: 0; font-size: 12.4px; color: var(--muted); }
.trace dl {
  margin: 8px 0 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 10px;
  font-size: 11.8px;
}
.trace dt { color: var(--muted); }
.trace dd { margin: 0; font-weight: 550; font-variant-numeric: tabular-nums; }
.trace-empty { font-size: 12.5px; color: var(--muted); margin: 0; }
.trace-empty.hide { display: none; }

/* --------------------------------------------------------------- narrow -- */
@media (max-width: 880px) {
  .stage { grid-template-columns: 1fr; gap: 22px; padding: 20px 16px 48px; }
  .inspector { position: static; }
  .phone { max-width: 360px; }
  .disclaimer { margin-right: 0; }
}
@media (max-width: 560px) {
  .topbar { padding: 14px 16px; padding-right: 84px; }
  .phone { padding: 0; border-radius: 0; background: none; box-shadow: none; max-width: none; }
  .phone-screen { border-radius: 14px; height: 74vh; min-height: 460px; }
}
