/* nelly-chat.css — full-screen WhatsApp-style conversation (whatsapp channel only).
 * WhatsApp LAYOUT, our theme: all colors come from olly-ui/tokens.css (--olly-*). No WhatsApp green;
 * the read tick uses the brand accent (--olly-info), not WhatsApp blue. */

.nchat {
  position: fixed; inset: 0; z-index: 1200;
  display: none; flex-direction: column;
  background: var(--olly-bg);
  font-family: var(--olly-font-sans);
  color: var(--olly-ink);
}
.nchat.is-open { display: flex; }

/* ── Header ─────────────────────────────────────────────────────────────── */
.nchat-header {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: var(--olly-sp-2);
  padding: var(--olly-sp-2) var(--olly-sp-3);
  padding-top: calc(var(--olly-sp-2) + env(safe-area-inset-top, 0px));
  background: var(--olly-surface);
  border-bottom: 1px solid var(--olly-line);
  box-shadow: var(--olly-shadow-1);
}
.nchat-back {
  border: 0; background: none; color: var(--olly-ink);
  display: flex; align-items: center; padding: 6px; cursor: pointer; border-radius: var(--olly-r-pill);
}
.nchat-back:active { background: var(--olly-line); }
.nchat-hd-avatar {
  width: 38px; height: 38px; border-radius: 50%; object-fit: cover; flex: 0 0 auto;
}
.nchat-hd-avatar--ph {
  display: flex; align-items: center; justify-content: center;
  background: var(--olly-tint-info); color: var(--olly-info);
  font-weight: var(--olly-fw-semibold); font-size: var(--olly-fs-md);
}
.nchat-hd-meta { min-width: 0; flex: 1 1 auto; }
.nchat-hd-name {
  font-weight: var(--olly-fw-semibold); font-size: var(--olly-fs-md);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nchat-hd-sub { font-size: var(--olly-fs-xs); color: var(--olly-muted); }

/* ── Message list ──────────────────────────────────────────────────────── */
.nchat-list {
  flex: 1 1 auto; overflow-y: auto; overflow-x: hidden;
  padding: var(--olly-sp-3) var(--olly-sp-3) var(--olly-sp-2);
  display: flex; flex-direction: column; gap: 2px;
  -webkit-overflow-scrolling: touch;
}
.nchat-loading { text-align: center; color: var(--olly-muted); padding: var(--olly-sp-5); }

.nchat-daysep { text-align: center; margin: var(--olly-sp-3) 0; }
.nchat-daysep span {
  display: inline-block; padding: 3px 12px; border-radius: var(--olly-r-pill);
  background: var(--olly-surface); border: 1px solid var(--olly-line);
  color: var(--olly-muted); font-size: var(--olly-fs-2xs);
}

/* Row = avatar gutter + bubble column. Grouped bubbles have 1px gap; tails get more space below. */
.nchat-row { display: flex; align-items: flex-end; gap: var(--olly-sp-2); max-width: 100%; }
.nchat-row.out { flex-direction: row-reverse; }
.nchat-row.is-tail { margin-bottom: var(--olly-sp-2); }
.nchat-avatar { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; }
.nchat-avatar--ph { background: var(--olly-tint-info); }
.nchat-avatar--sp { width: 26px; flex: 0 0 auto; background: none; } /* spacer to align grouped bubbles */

.nchat-bubble-wrap { display: flex; flex-direction: column; max-width: 78%; position: relative; }
.nchat-row.out .nchat-bubble-wrap { align-items: flex-end; }

.nchat-bubble {
  position: relative;
  padding: 6px 9px 5px; border-radius: 12px;
  background: var(--olly-surface); border: 1px solid var(--olly-line);
  font-size: var(--olly-fs-sm); line-height: 1.35; word-wrap: break-word; overflow-wrap: anywhere;
  box-shadow: var(--olly-shadow-1);
}
.nchat-row.out .nchat-bubble {
  background: var(--olly-tint-info); border-color: transparent; color: var(--olly-ink);
}
/* Tails: only the last bubble of a run gets a pointed corner. */
.nchat-row.in.is-tail  .nchat-bubble { border-bottom-left-radius: 3px; }
.nchat-row.out.is-tail .nchat-bubble { border-bottom-right-radius: 3px; }

.nchat-sender { font-size: var(--olly-fs-2xs); font-weight: var(--olly-fw-semibold); color: var(--olly-info); margin-bottom: 2px; }
.nchat-text { white-space: pre-wrap; }
.nchat-text a { color: var(--olly-info); text-decoration: none; }
.nchat-media { margin: -2px -3px 3px; border-radius: 9px; overflow: hidden; }
.nchat-media img, .nchat-media video { max-width: 100%; border-radius: 9px; display: block; }

.nchat-meta {
  display: inline-flex; align-items: center; gap: 3px; float: right;
  margin: 2px 0 -2px 8px; font-size: var(--olly-fs-2xs); color: var(--olly-muted);
}
.nchat-tick { font-size: 15px; line-height: 1; color: var(--olly-muted); }
.nchat-tick--read { color: var(--olly-info); }
.nchat-tick--err { color: var(--olly-bad); }

/* Link preview */
.nchat-lp { display: block; margin: 4px 0 2px; border-radius: 8px; overflow: hidden; border: 1px solid var(--olly-line); background: var(--olly-bg); text-decoration: none; color: inherit; }
.nchat-lp-img { height: 120px; background-size: cover; background-position: center; }
.nchat-lp-body { padding: 6px 8px; }
.nchat-lp-title { font-weight: var(--olly-fw-semibold); font-size: var(--olly-fs-xs); }
.nchat-lp-desc { font-size: var(--olly-fs-2xs); color: var(--olly-muted); max-height: 2.6em; overflow: hidden; }
.nchat-lp-site { font-size: var(--olly-fs-2xs); color: var(--olly-info); margin-top: 2px; }

/* Reactions */
.nchat-reacts { display: flex; gap: 3px; margin-top: -6px; margin-left: 6px; z-index: 1; }
.nchat-row.out .nchat-reacts { margin-left: 0; margin-right: 6px; justify-content: flex-end; }
.nchat-react-chip {
  display: inline-flex; align-items: center; gap: 2px;
  background: var(--olly-surface); border: 1px solid var(--olly-line);
  border-radius: var(--olly-r-pill); padding: 1px 6px; font-size: var(--olly-fs-2xs); cursor: pointer;
  box-shadow: var(--olly-shadow-1);
}
.nchat-react-n { color: var(--olly-muted); }
.nchat-react-add {
  position: absolute; top: 2px; opacity: 0; border: 0; background: none; color: var(--olly-muted);
  cursor: pointer; padding: 2px; transition: opacity .12s;
}
.nchat-row.in  .nchat-react-add { right: -26px; }
.nchat-row.out .nchat-react-add { left: -26px; }
.nchat-bubble-wrap:hover .nchat-react-add { opacity: 1; }
.nchat-react-add .material-icons-outlined { font-size: 18px; }

/* Typing indicator */
.nchat-typing { display: inline-flex; gap: 4px; align-items: center; padding: 8px 12px; margin: 2px 0; background: var(--olly-surface); border: 1px solid var(--olly-line); border-radius: 12px; width: fit-content; }
.nchat-typing[hidden] { display: none; }
.nchat-typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--olly-muted); animation: nchat-bounce 1.2s infinite; }
.nchat-typing span:nth-child(2) { animation-delay: .2s; }
.nchat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes nchat-bounce { 0%,60%,100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-4px); opacity: 1; } }

/* ── Action row (AI reply + quick chips) ───────────────────────────────── */
.nchat-actions {
  flex: 0 0 auto; display: flex; align-items: center; gap: var(--olly-sp-2);
  padding: var(--olly-sp-2) var(--olly-sp-3) 0; overflow-x: auto; white-space: nowrap;
}
.nchat-actbtn {
  display: inline-flex; align-items: center; gap: 4px; flex: 0 0 auto;
  background: var(--olly-tint-info); color: var(--olly-info); border: 0;
  border-radius: var(--olly-r-pill); padding: 5px 12px; font-size: var(--olly-fs-xs);
  font-weight: var(--olly-fw-medium); cursor: pointer;
}
.nchat-actbtn .material-icons-outlined { font-size: 16px; }
.nchat-chips { display: flex; gap: 6px; }
.nchat-chip {
  flex: 0 0 auto; background: var(--olly-surface); border: 1px solid var(--olly-line);
  border-radius: var(--olly-r-pill); padding: 5px 12px; font-size: var(--olly-fs-xs);
  color: var(--olly-ink); cursor: pointer;
}

/* ── Composer ──────────────────────────────────────────────────────────── */
.nchat-composer {
  flex: 0 0 auto; display: flex; align-items: flex-end; gap: 4px;
  padding: var(--olly-sp-2) var(--olly-sp-3);
  padding-bottom: calc(var(--olly-sp-2) + env(safe-area-inset-bottom, 0px));
  background: var(--olly-surface); border-top: 1px solid var(--olly-line);
}
.nchat-input {
  flex: 1 1 auto; resize: none; max-height: 140px;
  border: 1px solid var(--olly-line); border-radius: 20px;
  padding: 9px 14px; font: inherit; font-size: var(--olly-fs-sm);
  background: var(--olly-bg); color: var(--olly-ink); outline: none;
}
.nchat-send {
  flex: 0 0 auto; width: 42px; height: 42px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--olly-info); color: var(--olly-on-primary);
  display: flex; align-items: center; justify-content: center;
}
.nchat-send .material-icons-outlined { font-size: 20px; }

/* The attach tray reuses app.js's #nelly-attach-tray; keep it above the composer. */
.nchat .nelly-attach-tray:empty { display: none; }
.nchat .nelly-attach-tray { padding: 0 var(--olly-sp-3); }

@media (prefers-color-scheme: dark) {
  /* Tokens already carry dark values where defined; nothing hardcoded here to override. */
}
