/* retain scene: the customer record. Contact, deals, follow-ups, campaign template and
   prepaid credit wallet, tied to the conversation that created them. Every selector below
   is scoped under [data-app-scene="retain"] per the scene contract. */

[data-app-scene="retain"] .app-preview {
  --retain-amber: oklch(.8 .15 80);
  --retain-amber-tint: oklch(.8 .15 80 / .16);
  --retain-green: oklch(.72 .16 150);
  --retain-green-tint: oklch(.72 .16 150 / .16);
  --retain-blue-tint: oklch(.66 .18 263 / .15);
  font-variant-numeric: tabular-nums;
}

/* Layout shell */
[data-app-scene="retain"] .retain-body {
  display: flex;
  flex-direction: column;
  height: calc(100% - 42px);
  min-height: 0;
  padding: 10px;
  gap: 9px;
  overflow: hidden;
}

/* Identity strip */
[data-app-scene="retain"] .retain-identity {
  display: flex;
  flex: none;
  align-items: center;
  gap: 9px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--showcase-line);
}
[data-app-scene="retain"] .retain-avatar {
  display: grid;
  flex: none;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--retain-blue-tint);
  color: var(--showcase-blue);
  font-size: 10px;
  font-weight: 700;
}
[data-app-scene="retain"] img.retain-avatar {
  object-fit: cover;
  border: 1px solid var(--showcase-line);
}
/* The signed-in user badge in the shared topbar chrome: same slot every scene reuses,
   sized by the shared stylesheet, only the image treatment is ours to add. */
[data-app-scene="retain"] img.app-user {
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--showcase-line);
}
[data-app-scene="retain"] .retain-identity-main {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 4px;
}
[data-app-scene="retain"] .retain-name {
  overflow: hidden;
  color: var(--showcase-text);
  font-size: 11px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
[data-app-scene="retain"] .retain-channels { display: flex; gap: 4px; }
[data-app-scene="retain"] .retain-channel-pill {
  border: 1px solid var(--showcase-line);
  border-radius: 9px;
  padding: 2px 6px;
  color: var(--showcase-muted);
  font-size: 7px;
  font-weight: 500;
}
[data-app-scene="retain"] .retain-owner {
  display: flex;
  flex: none;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  text-align: end;
}
[data-app-scene="retain"] .retain-owner-label { color: var(--showcase-muted); font-size: 7px; }
[data-app-scene="retain"] .retain-owner-who { display: flex; align-items: center; gap: 4px; }
[data-app-scene="retain"] .retain-owner-avatar {
  display: grid;
  flex: none;
  place-items: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--retain-blue-tint);
  color: var(--showcase-blue);
  font-size: 6px;
  font-weight: 700;
  object-fit: cover;
  border: 1px solid var(--showcase-line);
}
[data-app-scene="retain"] .retain-owner-name { color: var(--showcase-text); font-size: 8px; font-weight: 600; }
[data-app-scene="retain"] .retain-more-btn {
  display: grid;
  flex: none;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: transparent;
  color: var(--showcase-muted);
  transition: background 180ms ease, color 180ms ease;
}
[data-app-scene="retain"] .retain-more-btn svg { width: 13px; height: 13px; }
[data-app-scene="retain"] .retain-more-btn:hover { background: var(--showcase-panel-2); color: var(--showcase-text); }

/* Two-column body */
[data-app-scene="retain"] .retain-columns {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  flex: 1;
  min-height: 0;
  gap: 10px;
}
[data-app-scene="retain"] .retain-col {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  gap: 9px;
}
[data-app-scene="retain"] .retain-block {
  display: flex;
  flex: none;
  min-width: 0;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--showcase-line);
  border-radius: 8px;
  background: oklch(.15 .012 264 / .55);
}

[data-app-scene="retain"] .retain-block > header {
  display: flex;
  flex: none;
  min-height: 28px;
  align-items: center;
  justify-content: space-between;
  padding: 6px 9px;
  border-bottom: 1px solid var(--showcase-line);
}
[data-app-scene="retain"] .retain-block > header strong { color: var(--showcase-text); font-size: 9px; font-weight: 700; }
[data-app-scene="retain"] .retain-block-count {
  border-radius: 10px;
  background: var(--showcase-panel-2);
  padding: 1px 6px;
  color: var(--showcase-muted);
  font-size: 7px;
  font-weight: 600;
}
[data-app-scene="retain"] .retain-add-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  border-radius: 6px;
  background: transparent;
  padding: 3px 7px 3px 5px;
  color: var(--showcase-muted);
  font-size: 7px;
  font-weight: 600;
  transition: background 180ms ease, color 180ms ease;
}
[data-app-scene="retain"] .retain-add-btn:hover { background: var(--showcase-panel-2); color: var(--showcase-text); }
[data-app-scene="retain"] .retain-add-btn kbd {
  border: 1px solid var(--showcase-line);
  border-radius: 4px;
  background: var(--showcase-panel-2);
  padding: 1px 4px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 7px;
  font-weight: 700;
}

/* Deals */
[data-app-scene="retain"] .retain-deal-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  column-gap: 8px;
  padding: 9px 9px;
  transition: background 180ms ease;
}
/* Fixed width on the deal-stage chip: it flips text (Proposal to Won) mid loop, and an
   "auto" grid column would resize with it, nudging the value column beside it. */
[data-app-scene="retain"] .retain-chip[data-deal-stage] { min-width: 58px; justify-content: center; }
[data-app-scene="retain"] .retain-deal-row + .retain-deal-row { border-top: 1px solid var(--showcase-line); }
[data-app-scene="retain"] .retain-deal-row:hover { background: oklch(.2 .025 264 / .5); }
[data-app-scene="retain"] .retain-deal-name {
  overflow: hidden;
  color: var(--showcase-text);
  font-size: 8px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}
[data-app-scene="retain"] .retain-deal-value { color: var(--showcase-text); font-size: 9px; font-weight: 700; text-align: end; }

/* Follow-ups */
[data-app-scene="retain"] .retain-followup-list {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin: 0;
  padding: 0;
  list-style: none;
}
[data-app-scene="retain"] .retain-followup-row {
  position: relative;
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 8px;
  padding: 10px 9px;
  transition: background 180ms ease;
}
/* Rows live one level deeper now (li > .retain-collapse > .retain-followup-row) so the
   collapse wrapper can own the height tween; the border rule moves to the list-item level. */
[data-app-scene="retain"] .retain-followup-list > li + li { border-top: 1px solid var(--showcase-line); }
[data-app-scene="retain"] .retain-followup-row:hover { background: oklch(.2 .025 264 / .5); }
[data-app-scene="retain"] .retain-followup-row.is-due::before {
  content: "";
  position: absolute;
  inset-block: 7px;
  inset-inline-start: 0;
  width: 2px;
  border-radius: 2px;
  background: var(--retain-amber);
}
[data-app-scene="retain"] .retain-due-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--retain-amber);
  box-shadow: 0 0 0 3px var(--retain-amber-tint);
}
[data-app-scene="retain"] .retain-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--showcase-line); }
[data-app-scene="retain"] .retain-fu-main { display: flex; min-width: 0; flex-direction: column; }
[data-app-scene="retain"] .retain-fu-title {
  overflow: hidden;
  color: var(--showcase-text);
  font-size: 8px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}
[data-app-scene="retain"] .retain-fu-meta {
  overflow: hidden;
  margin-top: 2px;
  color: var(--showcase-muted);
  font-size: 7px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Campaign template + credit wallet */
[data-app-scene="retain"] .retain-template-row {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 9px;
  border-bottom: 1px solid var(--showcase-line);
  transition: background 180ms ease;
}
[data-app-scene="retain"] .retain-template-row:hover { background: oklch(.2 .025 264 / .4); }
[data-app-scene="retain"] .retain-template-name {
  overflow: hidden;
  min-width: 0;
  color: var(--showcase-text);
  font-size: 8px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Fixed width on the template-status chip: it flips text (Pending review to Approved)
   mid loop, and its own shrink-to-fit width would nudge inside the row as it does. */
[data-app-scene="retain"] .retain-chip[data-template-status] { min-width: 76px; justify-content: center; }
[data-app-scene="retain"] .retain-wallet { padding: 7px 9px; }
[data-app-scene="retain"] .retain-wallet-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
[data-app-scene="retain"] .retain-wallet-label { color: var(--showcase-muted); font-size: 7px; }
[data-app-scene="retain"] .retain-wallet-amount { color: var(--showcase-text); font-size: 10px; font-weight: 700; }
[data-app-scene="retain"] .retain-ledger {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 6px 0 0;
  padding-top: 6px;
  border-top: 1px solid var(--showcase-line);
  list-style: none;
}
[data-app-scene="retain"] .retain-ledger:empty { display: none; margin: 0; padding: 0; border: 0; }
[data-app-scene="retain"] .retain-ledger-row { display: flex; align-items: center; gap: 6px; }
[data-app-scene="retain"] .retain-ledger-text {
  overflow: hidden;
  min-width: 0;
  flex: 1;
  color: var(--showcase-muted);
  font-size: 7px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
[data-app-scene="retain"] .retain-ledger-amount { flex: none; color: var(--showcase-text); font-size: 7px; font-weight: 600; }
[data-app-scene="retain"] .retain-ledger-time { flex: none; color: var(--showcase-muted); font-size: 7px; }
[data-app-scene="retain"] .retain-wallet-note { margin: 6px 0 0; color: var(--showcase-muted); font-size: 7px; line-height: 1.4; }

/* Activity */
[data-app-scene="retain"] .retain-activity-list {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin: 0;
  padding: 0;
  list-style: none;
}
[data-app-scene="retain"] .retain-activity-list > li + li { border-top: 1px solid var(--showcase-line); }
[data-app-scene="retain"] .retain-activity-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 9px;
  transition: background 180ms ease;
}
[data-app-scene="retain"] .retain-activity-row:hover { background: oklch(.2 .025 264 / .5); }
[data-app-scene="retain"] .retain-activity-text {
  overflow: hidden;
  min-width: 0;
  flex: 1;
  color: var(--showcase-text);
  font-size: 8px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}
[data-app-scene="retain"] .retain-activity-time { flex: none; color: var(--showcase-muted); font-size: 7px; }

/* Recent conversation: two lines lifted from the WhatsApp thread this record came from,
   the same visual language as the chat bubbles in the timeline scene, shrunk to a preview. */
[data-app-scene="retain"] .retain-conversation > header { min-height: 24px; gap: 6px; }
[data-app-scene="retain"] .retain-convo-preview {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 5px 8px;
}
[data-app-scene="retain"] .retain-convo-msg { display: flex; min-width: 0; max-width: 90%; flex-direction: column; gap: 2px; }
[data-app-scene="retain"] .retain-convo-msg-in { align-self: flex-start; align-items: flex-start; }
[data-app-scene="retain"] .retain-convo-msg-out { align-self: flex-end; align-items: flex-end; }
[data-app-scene="retain"] .retain-convo-text {
  overflow: hidden;
  min-width: 0;
  max-width: 100%;
  border-radius: 9px;
  padding: 4px 7px;
  color: var(--showcase-text);
  font-size: 8px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}
[data-app-scene="retain"] .retain-convo-msg-in .retain-convo-text {
  border: 1px solid var(--showcase-line);
  border-end-start-radius: 3px;
  background: var(--showcase-panel-2);
}
[data-app-scene="retain"] .retain-convo-msg-out .retain-convo-text {
  border-end-end-radius: 3px;
  background: var(--retain-blue-tint);
}
[data-app-scene="retain"] .retain-convo-time { padding: 0 2px; color: var(--showcase-muted); font-size: 7px; }

/* Status chips: 5px dot + sentence-case label */
[data-app-scene="retain"] .retain-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 20px;
  padding: 3px 8px;
  font-size: 7px;
  font-weight: 600;
  white-space: nowrap;
}
[data-app-scene="retain"] .retain-chip-sm { padding: 2px 7px; }
[data-app-scene="retain"] .retain-chip i { width: 5px; height: 5px; flex: none; border-radius: 50%; background: currentColor; }
[data-app-scene="retain"] .retain-chip-blue { background: var(--retain-blue-tint); color: var(--showcase-blue); }
[data-app-scene="retain"] .retain-chip-amber { background: var(--retain-amber-tint); color: var(--retain-amber); }
[data-app-scene="retain"] .retain-chip-green { background: var(--retain-green-tint); color: var(--retain-green); }

/* Entrance: settles in when the scene scrolls into view */
@keyframes retain-enter { from { opacity: .32; transform: translateY(12px); } to { opacity: 1; transform: none; } }
[data-app-scene="retain"] .app-preview.is-scene-active .retain-identity { animation: retain-enter 520ms 60ms cubic-bezier(.22,1,.36,1) both; }
[data-app-scene="retain"] .app-preview.is-scene-active .retain-deals { animation: retain-enter 520ms 150ms cubic-bezier(.22,1,.36,1) both; }
[data-app-scene="retain"] .app-preview.is-scene-active .retain-campaign { animation: retain-enter 520ms 210ms cubic-bezier(.22,1,.36,1) both; }
[data-app-scene="retain"] .app-preview.is-scene-active .retain-followups { animation: retain-enter 520ms 250ms cubic-bezier(.22,1,.36,1) both; }
[data-app-scene="retain"] .app-preview.is-scene-active .retain-conversation { animation: retain-enter 520ms 330ms cubic-bezier(.22,1,.36,1) both; }
[data-app-scene="retain"] .app-preview.is-scene-active .retain-activity { animation: retain-enter 520ms 380ms cubic-bezier(.22,1,.36,1) both; }
@media (prefers-reduced-motion: reduce) {
  [data-app-scene="retain"] .app-preview.is-scene-active .retain-identity,
  [data-app-scene="retain"] .app-preview.is-scene-active .retain-deals,
  [data-app-scene="retain"] .app-preview.is-scene-active .retain-campaign,
  [data-app-scene="retain"] .app-preview.is-scene-active .retain-followups,
  [data-app-scene="retain"] .app-preview.is-scene-active .retain-activity,
  [data-app-scene="retain"] .app-preview.is-scene-active .retain-conversation { animation: none; }
}

/* Loop-driven row and chip motion. A row that the loop inserts or removes lives in
   li.retain-collapse: the wrapper's own grid-template-rows tweens 0fr to 1fr (its child
   carries min-height:0 and overflow:hidden) so it claims or releases its slot in the list
   over the same ~360ms instead of the list snapping to a new height. The visible content
   riding inside it still gets the opacity/transform polish via is-entering/is-leaving. */
@keyframes retain-row-enter { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes retain-row-leave { to { opacity: 0; transform: translateY(-4px); } }
@keyframes retain-pop { 0% { transform: scale(.6); opacity: .4; } 60% { transform: scale(1.08); opacity: 1; } 100% { transform: scale(1); } }
[data-app-scene="retain"] .is-entering { animation: retain-row-enter 320ms cubic-bezier(.22,1,.36,1) both; }
[data-app-scene="retain"] .is-leaving { animation: retain-row-leave 220ms ease both; }
[data-app-scene="retain"] .is-popping { animation: retain-pop 420ms cubic-bezier(.22,1,.36,1); }

/* Collapse wrapper: a row inserted or removed by the loop claims or releases its own
   vertical space instead of snapping the list, so nothing below it jumps. The li is the
   wrapper (grid-template-rows tweening 0fr to 1fr); its one child is the clipped, height-
   contributing box; .is-entering/.is-leaving (above) handle that child's own reveal so
   the two motions (space opening, content fading in) read as one settle. */
[data-app-scene="retain"] .retain-collapse {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 360ms cubic-bezier(.22,1,.36,1);
}
[data-app-scene="retain"] .retain-collapse.is-open { grid-template-rows: 1fr; }
[data-app-scene="retain"] .retain-row-collapse-inner { min-height: 0; overflow: hidden; }
@media (prefers-reduced-motion: reduce) {
  [data-app-scene="retain"] .retain-collapse { transition: none; }
}

/* Idle life: a breathing dot on the due follow-up, a quiet pulse while a chip awaits review */
@media (prefers-reduced-motion: no-preference) {
  [data-app-scene="retain"] .retain-due-dot { animation: retain-breathe 2.4s ease-in-out infinite; }
  [data-app-scene="retain"] .retain-chip-amber i { animation: retain-breathe-dot 2.4s ease-in-out infinite; }
}
@keyframes retain-breathe { 0%, 100% { box-shadow: 0 0 0 3px var(--retain-amber-tint); } 50% { box-shadow: 0 0 0 6px oklch(.8 .15 80 / .05); } }
@keyframes retain-breathe-dot { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }

/* 1024 px page: tighten before the phone layout kicks in */
@container app-scene (max-width: 600px) {
  [data-app-scene="retain"] .retain-body { padding: 9px; gap: 8px; }
  [data-app-scene="retain"] .retain-columns { gap: 8px; }
  [data-app-scene="retain"] .retain-block > header { padding: 5px 8px; }
  [data-app-scene="retain"] .retain-deal-row,
  [data-app-scene="retain"] .retain-followup-row,
  [data-app-scene="retain"] .retain-template-row,
  [data-app-scene="retain"] .retain-activity-row { padding: 6px 8px; }
  [data-app-scene="retain"] .retain-wallet { padding: 7px 8px; }
  [data-app-scene="retain"] .retain-convo-preview { padding: 4px 8px; gap: 3px; }
}

/* Phone: one focused column, most important blocks first, type stepped up a notch.
   Content is capped hard here (one row per list, no ledger detail) because the host
   is only 340x370: anything left to grow-and-clip would silently lose rows behind
   the root's overflow:hidden instead of resizing, so priority trims happen in markup
   reach, not in a scrollbar that does not exist. */
@container app-scene (max-width: 420px) {
  [data-app-scene="retain"] .retain-body { padding: 8px; gap: 5px; }
  [data-app-scene="retain"] .retain-columns { display: flex; flex-direction: column; gap: 5px; }
  [data-app-scene="retain"] .retain-col { display: contents; }
  [data-app-scene="retain"] .retain-identity { padding-bottom: 5px; }
  [data-app-scene="retain"] .retain-identity-main { flex-direction: row; flex-wrap: wrap; align-items: baseline; gap: 6px; }
  [data-app-scene="retain"] .retain-owner { display: none; }
  [data-app-scene="retain"] .retain-block > header { min-height: 0; padding: 4px 8px; }
  [data-app-scene="retain"] .retain-deal-row,
  [data-app-scene="retain"] .retain-followup-row,
  [data-app-scene="retain"] .retain-template-row { padding: 5px 8px; }
  [data-app-scene="retain"] .retain-wallet { padding: 6px 8px; }
  /* The hard row trims only apply on phone PAGES (short 340x370 host). A tablet page
     (768) gives a narrow-but-tall 388x502 host: same single column, but the rows stay,
     otherwise a blank band is left under Activity. The container cannot query height
     (inline-size container), so the page width stands in for it. */
  /* Every narrow host: the conversation preview, ledger detail and wallet note are
     desktop fill-the-column additions and step aside rather than fight for room. */
  [data-app-scene="retain"] .retain-ledger,
  [data-app-scene="retain"] .retain-wallet-note,
  [data-app-scene="retain"] .retain-conversation,
  [data-app-scene="retain"] .retain-followup-list li:nth-child(n+3),
  [data-app-scene="retain"] .retain-activity-list li:nth-child(n+4) { display: none; }
  @media (max-width: 640px) {
    [data-app-scene="retain"] .retain-activity-list li:nth-child(n+3) { display: none; }
    [data-app-scene="retain"] .retain-deal-row[data-deal="2"] { display: none; }
    [data-app-scene="retain"] .retain-followup-list li:nth-child(n+2) { display: none; }
    [data-app-scene="retain"] .retain-activity-list li:nth-child(n+2) { display: none; }
  }
  [data-app-scene="retain"] .retain-name { font-size: 12px; }
  [data-app-scene="retain"] .retain-block > header strong { font-size: 10px; }
  [data-app-scene="retain"] .retain-deal-name,
  [data-app-scene="retain"] .retain-fu-title,
  [data-app-scene="retain"] .retain-template-name,
  [data-app-scene="retain"] .retain-activity-text { font-size: 9px; }
  [data-app-scene="retain"] .retain-deal-value { font-size: 10px; }
  [data-app-scene="retain"] .retain-wallet-amount { font-size: 11px; }
  [data-app-scene="retain"] .retain-fu-meta,
  [data-app-scene="retain"] .retain-channel-pill,
  [data-app-scene="retain"] .retain-chip,
  [data-app-scene="retain"] .retain-activity-time { font-size: 8px; }
}
