/* Yoyo — iPhone Messages replica. Plain CSS, no build step, no external assets. */

/* The `hidden` attribute must always win. Without this, any element whose own
   rule sets a display (the sheet backdrop's flex, a button's inline-flex)
   overrides the UA's [hidden] display:none — which once left an invisible
   full-screen backdrop at z-index 40 swallowing every tap on the app. */
[hidden] { display: none !important; }

:root {
  --canvas: #ffffff;
  --text: #000000;
  --blue: #0A84FF;
  --bubble-them: #E9E9EB;
  --bubble-them-text: #0b0b0f;
  --grey-cap: #8E8E93;
  --hairline: rgba(0, 0, 0, 0.14);
  --nav-bg: rgba(249, 249, 249, 0.84);
  --card-bg: #F2F2F7;
  --agent-bg: #E7F0EB;
  --agent-text: #23443A;
  --agent-cap: #55806F;
  --sheet-bg: #F2F2F7;
  --field-bg: #ffffff;
  --stage: #d9d9de;
  --good: #248A3D;
  --warn: #C76A00;
  --bad: #D70015;
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #000000;
    --text: #ffffff;
    --bubble-them: #3B3B3D;
    --bubble-them-text: #ffffff;
    --grey-cap: #98989F;
    --hairline: rgba(255, 255, 255, 0.16);
    --nav-bg: rgba(18, 18, 18, 0.82);
    --card-bg: #1C1C1E;
    --agent-bg: #1C2B26;
    --agent-text: #C6E0D6;
    --agent-cap: #74A692;
    --sheet-bg: #1C1C1E;
    --field-bg: #2C2C2E;
    --stage: #0b0b0c;
    --good: #30D158;
    --warn: #FF9F0A;
    --bad: #FF453A;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--stage);
  color: var(--text);
  font-family: -apple-system, "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.stage {
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Phone shape: full-viewport on small screens, 390x844 device on wide ones */
.phone {
  position: relative;
  width: 100%;
  height: 100dvh;
  background: var(--canvas);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (min-width: 700px) {
  .phone {
    width: 390px;
    height: 844px;
    max-height: calc(100dvh - 48px);
    border-radius: 55px;
    border: 1px solid var(--hairline);
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.28), 0 4px 14px rgba(0, 0, 0, 0.18);
  }
}

/* ---------- Header ---------- */

.nav {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 52px 1fr 84px;
  align-items: center;
  padding: calc(16px + env(safe-area-inset-top)) 10px 10px;
  background: var(--nav-bg);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  backdrop-filter: blur(22px) saturate(180%);
  border-bottom: 0.5px solid var(--hairline);
}

.nav-back {
  color: var(--blue);
  display: flex;
  justify-content: center;
  align-items: center;
}

.nav-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 0;
}

.avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: linear-gradient(180deg, #a9b2c4, #7e8aa0);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 25px;
  line-height: 1;
  user-select: none;
}

.nav-name {
  font-size: 11px;
  color: var(--text);
  white-space: nowrap;
}

.nav-chev { color: var(--grey-cap); font-size: 12px; }

.nav-right {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  padding-right: 8px;
}

.iconbtn {
  appearance: none;
  background: none;
  border: none;
  padding: 6px;
  color: var(--blue);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
}

/* ---------- Thread ---------- */

.thread {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: calc(96px + env(safe-area-inset-top)) 0 10px;
  overscroll-behavior: contain;
}

.datechip {
  text-align: center;
  font-size: 11px;
  color: var(--grey-cap);
  margin: 10px 24px 4px;
}

.datechip strong { font-weight: 600; }

/* message rows */

.msg {
  display: flex;
  margin: 8px 12px 0;
}

.msg.grouped { margin-top: 2px; }

.from-me { justify-content: flex-end; }
.from-them { justify-content: flex-start; }

.bubble {
  position: relative;
  max-width: 75%;
  padding: 7px 12px;
  border-radius: 18px;
  font-size: 17px;
  line-height: 1.28;
  overflow-wrap: break-word;
  word-break: break-word;
}

.from-me .bubble { background: var(--blue); color: #fff; }
.from-them .bubble { background: var(--bubble-them); color: var(--bubble-them-text); }

.bubble-inner { position: relative; z-index: 1; white-space: pre-wrap; }
.bubble-inner br + br { line-height: 0.6; }

.bubble-inner code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.88em;
  background: rgba(127, 127, 127, 0.18);
  border-radius: 4px;
  padding: 1px 4px;
}

.from-me .bubble-inner a { color: #fff; }
.from-them .bubble-inner a { color: var(--blue); }

/* real tails, last bubble of each group only */

.bubble.tail::before,
.bubble.tail::after {
  content: "";
  position: absolute;
  bottom: 0;
  height: 20px;
  z-index: 0;
}

.from-me .bubble.tail::before {
  right: -7px;
  width: 20px;
  background: var(--blue);
  border-bottom-left-radius: 16px 14px;
}
.from-me .bubble.tail::after {
  right: -26px;
  width: 26px;
  background: var(--canvas);
  border-bottom-left-radius: 10px;
}

.from-them .bubble.tail::before {
  left: -7px;
  width: 20px;
  background: var(--bubble-them);
  border-bottom-right-radius: 16px 14px;
}
.from-them .bubble.tail::after {
  left: -26px;
  width: 26px;
  background: var(--canvas);
  border-bottom-right-radius: 10px;
}

/* The trust line on every money card. */

.card-secured {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--hairline);
  font-size: 10.5px;
  letter-spacing: 0.02em;
  color: var(--grey-cap);
}
.card-secured svg {
  width: 15px;
  height: 15px;
  border-radius: 4px;
  flex: none;
}
.card-secured b { font-weight: 600; color: var(--text); }

/* The delegated agent's words: collapsed behind a small disclosure, tinted
   so an expanded one never passes for a Yoyo bubble. */

.agent-fold {
  margin: 8px 16px 0;
  max-width: 78%;
}

.agent-label {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--agent-cap);
  cursor: pointer;
  list-style: none;
  -webkit-user-select: none;
  user-select: none;
  padding: 2px 8px 2px 0;
}
.agent-label::-webkit-details-marker { display: none; }
.agent-label::before {
  content: "▸";
  display: inline-block;
  margin-right: 5px;
  transition: transform 0.15s ease;
}
.agent-fold[open] .agent-label::before { transform: rotate(90deg); }
.agent-label:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 4px; }

.agent-bubble {
  margin-top: 4px;
  background: var(--agent-bg);
  color: var(--agent-text);
  border-radius: 18px;
  padding: 8px 12px;
  font-size: 15px;
  line-height: 1.35;
  width: fit-content;
}

/* delivered caption */

.delivered {
  text-align: right;
  font-size: 11px;
  font-weight: 500;
  color: var(--grey-cap);
  margin: 2px 16px 0;
}

/* centered system lines (notices, delegate) */

.sysline {
  text-align: center;
  font-size: 11px;
  color: var(--grey-cap);
  margin: 12px 28px 0;
  line-height: 1.4;
}

.sysline.tone-good { color: var(--good); }
.sysline.tone-warn { color: var(--warn); }
.sysline.tone-bad { color: var(--bad); }

/* typing indicator */

.typing .bubble { padding: 11px 14px; }

.tdot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--grey-cap);
  margin-right: 4px;
  vertical-align: middle;
  animation: tpulse 1.2s infinite ease-in-out;
}
.tdot:last-child { margin-right: 0; }
.tdot:nth-child(2) { animation-delay: 0.18s; }
.tdot:nth-child(3) { animation-delay: 0.36s; }

@keyframes tpulse {
  0%, 60%, 100% { opacity: 0.35; transform: scale(0.88); }
  30% { opacity: 1; transform: scale(1); }
}

/* ---------- Money cards (rich-link style) ---------- */

.card-row { margin-top: 8px; }

.card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(84%, 300px);
  background: var(--card-bg);
  border: 0.5px solid var(--hairline);
  border-radius: 16px;
  padding: 12px 14px;
  text-decoration: none;
  color: var(--text);
}

a.card { cursor: pointer; }

.card-main { flex: 1; min-width: 0; }

.card-mark {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--grey-cap);
  margin-bottom: 3px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.25;
}

.card-sub {
  font-size: 12px;
  color: var(--grey-cap);
  margin-top: 2px;
  line-height: 1.35;
}

.card-chev {
  color: var(--grey-cap);
  font-size: 22px;
  line-height: 1;
  flex: none;
}

.card .chip {
  font-size: 12px;
  color: var(--grey-cap);
  margin-top: 5px;
}

.approve-btn {
  appearance: none;
  margin-top: 9px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 7px 14px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.card.spent,
.card.concluded { opacity: 0.55; }
a.card.spent { pointer-events: none; }
.card.retired { opacity: 0.8; }

/* Connected: a record of the link, not a dimmed corpse — full opacity,
   check instead of chevron, tinted title. */
.card.connected { opacity: 1; }
.card.connected .card-title { color: var(--agent-cap); }
.card.connected .card-chev { color: var(--agent-cap); }

/* ---------- Composer ---------- */

.composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  padding: 8px 14px calc(16px + env(safe-area-inset-bottom));
  background: var(--canvas);
}

.pill {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--hairline);
  border-radius: 20px;
  padding: 4px 4px 4px 14px;
  min-height: 36px;
  background: var(--canvas);
}

#input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  font-size: 17px;
  font-family: inherit;
  color: var(--text);
  padding: 4px 0;
}

#input::placeholder { color: var(--grey-cap); }

.send {
  appearance: none;
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--blue);
  border: none;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.composer.has-text .send { display: flex; }

/* ---------- Settings sheet ---------- */

.sheet-backdrop {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  opacity: 0;
  transition: opacity 0.22s ease;
}

.sheet-backdrop.open { opacity: 1; }

.sheet {
  width: 100%;
  max-height: 80%;
  overflow-y: auto;
  background: var(--sheet-bg);
  border-radius: 16px 16px 0 0;
  padding: 6px 18px calc(20px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.3, 1);
}

.sheet-backdrop.open .sheet { transform: none; }

.grabber {
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: var(--grey-cap);
  opacity: 0.5;
  margin: 6px auto 10px;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.sheet-head h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.donebtn {
  appearance: none;
  background: none;
  border: none;
  color: var(--blue);
  font-size: 17px;
  font-weight: 600;
  font-family: inherit;
  padding: 6px 2px;
  cursor: pointer;
}

.group { margin-top: 14px; }

.group h3 {
  margin: 0 0 6px 4px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--grey-cap);
}

.grouprows {
  background: var(--canvas);
  border-radius: 12px;
  padding: 12px 14px;
  border: 0.5px solid var(--hairline);
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  padding: 3px 0;
  min-width: 0;
}

.rowmain { font-weight: 600; }

.row.small { font-size: 13px; }

.muted { color: var(--grey-cap); }

.dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--grey-cap);
}
.dot.live { background: var(--good); }

.keyform {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.keyform input {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: var(--field-bg);
  border: 0.5px solid var(--hairline);
  border-radius: 10px;
  padding: 8px 10px;
  outline: none;
}

.btn {
  appearance: none;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.btn-secondary {
  background: transparent;
  color: var(--blue);
  border: 1px solid var(--hairline);
}

.btn-danger {
  background: transparent;
  color: var(--bad);
  border: 1px solid var(--hairline);
  margin-top: 10px;
}

.err {
  color: var(--bad);
  font-size: 13px;
  margin-top: 8px;
}

.conn-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  padding: 3px 0;
  min-width: 0;
}

.conn-row .k { color: var(--grey-cap); flex: none; }
.conn-row .v {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
}

/* ---------- Focus + motion ---------- */

.iconbtn:focus-visible,
.send:focus-visible,
.btn:focus-visible,
.donebtn:focus-visible,
.approve-btn:focus-visible,
a.card:focus-visible,
.keyform input:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

/* The composer input's visible focus state is the pill border darkening
   (below) — an outline ring here would double-border the pill, which is
   exactly what Messages doesn't look like. */
#input:focus-visible { outline: none; }

.pill:focus-within { border-color: var(--grey-cap); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
  .tdot { opacity: 0.7; }
}
