/* ============================================================
   Puna Page Chat — feedback-chat widget chrome (BL-318 widget leg).

   Spec: _operating/_pending/BL-318-page-chat-spec.md § Widget.
   Two-copy module pattern: canonical source
     website/_components/feedback-chat/widget.css
   kept byte-identical to
     app/shared/feedback-chat/widget.css.

   Component-scoped palette per _config/design-tokens.md — tokens
   declared on .fc-root itself, never on :root. Canonical brand
   values resolve from design-tokens.css when the consuming page
   loads it; inline hex fallbacks keep the widget honest on a page
   that hasn't (e.g. a smoke harness).

   Placement is the CONSUMER's: the app mounts the launcher in the
   topbar (top-right chrome); tools mounts it fixed bottom-left,
   safe-area aware. Panel: 380px slide-in desktop; full sheet under
   640px (100dvh + visualViewport re-size handled in widget.js).

   Authored 2026-07-29 by 2-W2 (seat-2 builder spawn).
   ============================================================ */

.fc-root {
  --fc-bg:            linear-gradient(180deg, rgba(8, 18, 33, 0.97), rgba(11, 26, 46, 0.97));
  --fc-bg-flat:       #0b1a2e;
  --fc-navy-deep:     var(--navy-deep, #060f1d);
  --fc-cyan:          var(--cyan, #00c8c8);
  --fc-cyan-bright:   var(--cyan-bright, #00e5e5);
  --fc-cyan-dim:      var(--cyan-dim, rgba(0, 200, 200, 0.12));
  --fc-text:          var(--white, #f0f4f8);
  --fc-text-soft:     var(--white-soft, #cbd6e6);
  --fc-text-muted:    var(--white-muted, #9babc4);
  --fc-text-dim:      var(--white-dim, #8794ad);
  --fc-border:        var(--border-light, rgba(255, 255, 255, 0.10));
  --fc-border-soft:   var(--border, rgba(255, 255, 255, 0.06));
  --fc-warn:          var(--warn, #ff5c5c);
  --fc-radius:        8px;
  --fc-font:          var(--font-body, 'Inter', -apple-system, sans-serif);
  --fc-z:             9400; /* above page chrome; below nothing it needs to yield to */
  font-family: var(--fc-font);
}

/* ---------------- Launcher ---------------- */

/* Base launcher button — quiet at rest, cyan on attention (house
   discipline). Consumers add ONE placement class:
   .fc-launcher--chrome  → inline chrome button (app topbar)
   .fc-launcher--fixed   → fixed bottom-left pill (tools pages)   */
.fc-launcher {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--fc-border-soft);
  border-radius: 999px;
  color: var(--fc-text-soft);
  font-family: var(--fc-font);
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0.01em;
  line-height: 1;
  cursor: pointer;
  position: relative;
  transition: border-color 0.2s, color 0.2s, background 0.2s, box-shadow 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.fc-launcher:hover,
.fc-launcher:focus-visible {
  color: var(--fc-text);
  border-color: rgba(0, 200, 200, 0.45);
  background: var(--fc-cyan-dim);
}
.fc-launcher:focus-visible {
  outline: 2px solid var(--fc-cyan);
  outline-offset: 2px;
}
.fc-launcher.is-open {
  color: var(--fc-text);
  border-color: var(--fc-cyan);
  background: var(--fc-cyan-dim);
}
.fc-launcher-ic { display: inline-flex; }
.fc-launcher-ic svg { display: block; }

/* Unread badge on the launcher — the spec's durable-cursor badge. */
.fc-launcher-badge {
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--fc-cyan);
  color: var(--fc-navy-deep);
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.fc-launcher-badge[hidden] { display: none; }

/* Fixed placement (tools/website pages) — BOTTOM-LEFT, safe-area aware. */
.fc-launcher--fixed {
  position: fixed;
  left: calc(14px + env(safe-area-inset-left, 0px));
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  z-index: var(--fc-z);
  background: var(--fc-bg);
  border-color: var(--fc-border);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 9px 14px;
  font-size: 13px;
}
/* Pages with a bottom-anchored bar (the /tools adviser bar stretches
   edge-to-edge under 720px) opt in to clearing it on small screens. */
@media (max-width: 719px) {
  .fc-root.fc-clear-bottom-bar .fc-launcher--fixed {
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }
}

/* ---------------- Panel ---------------- */

/* BL-318 polish 2026-07-29 (2-W3) — COMPOSER CLIPPING.
   Measured from source on the REAL app page (headless Chromium over
   app/index.html + css/app.css with body.pga-ready, viewport 1512x791):
   the panel ran `top:0; bottom:0` — the LAYOUT viewport — so the
   composer landed flush on the viewport edge (compose bottom ==
   innerHeight) inside the app's reserved bottom band, where .pga-bar
   sits. Every other app surface stops above that band
   (#map { bottom: var(--bar-band-h) }); this panel was the exception.
   Fix = the spec's 100dvh discipline at EVERY width (it was <640px
   only): the panel tracks the VISUAL viewport — mobile URL-bar
   collapse, on-screen keyboard, desktop pinch-zoom — instead of the
   layout one. widget.js publishes --fc-vvh from visualViewport on
   every surface; 100dvh is the no-JS fallback, 100vh the pre-dvh one. */
.fc-panel {
  position: fixed;
  top: 0;
  width: 380px;
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  height: var(--fc-vvh, 100dvh);
  max-height: 100dvh;
  z-index: var(--fc-z);
  display: flex;
  flex-direction: column;
  /* Nothing paints past the panel box; the composer is the last child
     and must never be what overflows. */
  overflow: hidden;
  background: var(--fc-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: var(--fc-text);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0.28, 1), visibility 0.28s;
  visibility: hidden;
}
.fc-panel--right { right: 0; border-left: 1px solid var(--fc-border); transform: translateX(102%); }
.fc-panel--left  { left: 0;  border-right: 1px solid var(--fc-border); transform: translateX(-102%); }
.fc-root.is-open .fc-panel { transform: translateX(0); visibility: visible; }

@media (prefers-reduced-motion: reduce) {
  .fc-panel { transition: none; }
  .fc-launcher { transition: none; }
}

/* Full sheet on mobile (spec: 100dvh + visualViewport; widget.js sets
   --fc-vvh from visualViewport so the keyboard never hides the composer). */
@media (max-width: 639px) {
  .fc-panel,
  .fc-panel--right,
  .fc-panel--left {
    left: 0;
    right: 0;
    width: 100%;
    top: auto;
    bottom: 0;
    height: 100dvh;
    height: var(--fc-vvh, 100dvh);
    border-left: none;
    border-right: none;
    border-top: 1px solid var(--fc-border);
    transform: translateY(102%);
  }
  .fc-root.is-open .fc-panel { transform: translateY(0); }
}

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

.fc-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px calc(10px + env(safe-area-inset-top, 0px) * 0) 16px;
  border-bottom: 1px solid var(--fc-border-soft);
  flex: 0 0 auto;
}
.fc-head-title {
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--fc-text);
}
.fc-head-page {
  font-size: 11px;
  color: var(--fc-text-dim);
  font-family: var(--font-mono, 'JetBrains Mono', monospace);
  padding: 2px 7px;
  border: 1px solid var(--fc-border-soft);
  border-radius: 999px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 46%;
}
.fc-head-spacer { flex: 1; }
.fc-close {
  background: none;
  border: none;
  color: var(--fc-text-dim);
  font-size: 18px;
  line-height: 1;
  padding: 6px 8px;
  cursor: pointer;
  border-radius: 6px;
}
.fc-close:hover { color: var(--fc-text); background: rgba(255, 255, 255, 0.06); }
.fc-close:focus-visible { outline: 2px solid var(--fc-cyan); outline-offset: 1px; }

/* ---------------- Message list ---------------- */

.fc-list {
  flex: 1 1 auto;
  /* min-height:0 completes the flex chain panel → list-shell → list.
     `overflow-y:auto` already zeroes this box's automatic minimum size,
     so this is belt-and-braces — but it is the line that stops a future
     `overflow:visible` edit from silently pushing the composer out of
     the panel again. */
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px 14px 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.14) transparent;
  position: relative;
}
.fc-list::-webkit-scrollbar { width: 8px; }
.fc-list::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.14); border-radius: 4px; }

.fc-day-spin,
.fc-older-loading {
  text-align: center;
  color: var(--fc-text-dim);
  font-size: 11px;
  padding: 8px 0;
}

/* Empty state — spec copy, verbatim. Two lines (BL-318 polish): the
   ask carries the weight, the promise sits under it. */
.fc-empty {
  margin: auto;
  padding: 28px 26px;
  text-align: center;
  color: var(--fc-text-muted);
  font-size: 13px;
  line-height: 1.65;
}
.fc-empty-ic { font-size: 20px; color: var(--fc-cyan); margin-bottom: 10px; }
.fc-empty-l1 {
  color: var(--fc-text);
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.5;
}
.fc-empty-l2 {
  margin-top: 4px;
  color: var(--fc-text-muted);
  font-size: 12.5px;
  line-height: 1.55;
}

/* One message row. Grouped rows (same sender ≤5min) skip the header.
   position:relative anchors the own-message Edit/Delete controls, which
   must sit on the ROW (grouped rows have no header to hang them on). */
.fc-msg { padding: 1px 0; position: relative; }
.fc-msg-head {
  display: flex;
  align-items: baseline;
  gap: 7px;
  margin: 10px 0 2px;
}
.fc-msg-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--fc-text-soft);
}
.fc-msg--bot .fc-msg-name { color: var(--fc-cyan-bright); }
.fc-badge-team,
.fc-badge-bot {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 1.5px 6px;
  border-radius: 999px;
  line-height: 1.5;
}
.fc-badge-team { color: var(--fc-cyan-bright); background: var(--fc-cyan-dim); border: 1px solid rgba(0, 200, 200, 0.35); }
.fc-badge-bot  { color: var(--fc-text-muted); background: rgba(255, 255, 255, 0.05); border: 1px solid var(--fc-border-soft); }

/* Timestamp doubles as the #msg-<id> permalink. */
.fc-msg-time {
  font-size: 10.5px;
  color: var(--fc-text-dim);
  text-decoration: none;
  font-variant-numeric: tabular-nums;
}
.fc-msg-time:hover { color: var(--fc-cyan); text-decoration: underline; }

.fc-msg-body {
  font-size: 13px;
  line-height: 1.55;
  color: var(--fc-text);
  white-space: pre-wrap;
  word-wrap: break-word;
  padding: 2px 0;
}
.fc-msg--bot .fc-msg-body {
  color: var(--fc-text-soft);
  border-left: 2px solid rgba(0, 200, 200, 0.45);
  padding-left: 9px;
}
.fc-msg.is-pending .fc-msg-body { opacity: 0.55; }
.fc-msg.is-failed .fc-msg-body { opacity: 0.7; }
.fc-msg-failed-note {
  font-size: 11px;
  color: var(--fc-warn);
}
.fc-msg-retry {
  background: none;
  border: none;
  color: var(--fc-cyan);
  font-size: 11px;
  cursor: pointer;
  padding: 0 2px;
  text-decoration: underline;
}

/* ---- Own-message controls: Edit + Delete (BL-318 polish) ----
   Quiet by default; revealed on hover (fine pointers) or after a
   long-press (coarse pointers, .is-touched set by widget.js). Only
   .fc-msg--own carries them — the bot and other people's messages get
   neither control, so there is nothing to discover and nothing to
   mis-click. */
.fc-msg-tools {
  position: absolute;
  top: 0;
  right: 0;
  display: none;
  align-items: center;
  gap: 2px;
  padding: 1px 2px;
  border-radius: 6px;
  background: rgba(6, 15, 29, 0.92);
  border: 1px solid var(--fc-border-soft);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
.fc-msg--own:hover > .fc-msg-tools,
.fc-msg--own:focus-within > .fc-msg-tools,
.fc-msg--own.is-touched > .fc-msg-tools { display: flex; }
.fc-msg-act {
  background: none;
  border: none;
  color: var(--fc-text-dim);
  font-family: var(--fc-font);
  font-size: 10.5px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
}
.fc-msg-act:hover { color: var(--fc-text); background: rgba(255, 255, 255, 0.07); }
.fc-msg-act:focus-visible { outline: 2px solid var(--fc-cyan); outline-offset: 1px; }
.fc-msg-act--danger:hover { color: var(--fc-warn); background: rgba(255, 92, 92, 0.10); }
.fc-msg-act--confirm { color: var(--fc-warn); }
.fc-msg-confirm {
  color: var(--fc-text-dim);
  font-size: 10.5px;
  padding: 0 3px 0 5px;
}

/* "edited" marker — quiet, never a badge. */
.fc-msg-edited {
  font-size: 10px;
  color: var(--fc-text-dim);
  font-style: italic;
}

/* Soft-delete tombstone. The row stays (the thread's shape is true);
   the content does not. */
.fc-tombstone {
  font-size: 12px;
  font-style: italic;
  color: var(--fc-text-dim);
  padding: 2px 0;
}

/* Inline editor — same metrics as the composer input so the edit feels
   like the same surface, not a modal. */
.fc-msg-edit {
  display: block;
  width: 100%;
  resize: none;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(0, 200, 200, 0.45);
  border-radius: var(--fc-radius);
  color: var(--fc-text);
  font-family: var(--fc-font);
  font-size: 13px;
  line-height: 1.45;
  padding: 7px 10px;
  min-height: 34px;
  max-height: 160px;
  margin: 2px 0;
}
.fc-msg-edit:focus { outline: none; border-color: var(--fc-cyan); }
.fc-edit-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 1px 0 3px;
}
.fc-edit-save,
.fc-edit-cancel {
  border: 1px solid var(--fc-border-soft);
  border-radius: 5px;
  font-family: var(--fc-font);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  cursor: pointer;
}
.fc-edit-save { background: var(--fc-cyan); color: var(--fc-navy-deep); border-color: transparent; }
.fc-edit-save:hover { background: var(--fc-cyan-bright); }
.fc-edit-cancel { background: none; color: var(--fc-text-dim); }
.fc-edit-cancel:hover { color: var(--fc-text); }
.fc-edit-hint { font-size: 10px; color: var(--fc-text-dim); }

/* Permalink target flash */
.fc-msg.is-highlit {
  animation: fc-highlight 2.4s ease-out 1;
  border-radius: 6px;
}
@keyframes fc-highlight {
  0% { background: rgba(0, 200, 200, 0.16); }
  100% { background: transparent; }
}
@media (prefers-reduced-motion: reduce) {
  .fc-msg.is-highlit { animation: none; background: rgba(0, 200, 200, 0.10); }
}

/* FB reference chip (triage filed the message). */
.fc-fbref {
  display: inline-block;
  margin-left: 6px;
  font-size: 10px;
  font-weight: 600;
  font-family: var(--font-mono, 'JetBrains Mono', monospace);
  color: var(--fc-cyan-bright);
  background: var(--fc-cyan-dim);
  border: 1px solid rgba(0, 200, 200, 0.3);
  border-radius: 4px;
  padding: 0.5px 5px;
  vertical-align: 1px;
}

/* Reply context (bot replies reference the reported message). */
.fc-replyctx {
  font-size: 11px;
  color: var(--fc-text-dim);
  border-left: 2px solid var(--fc-border);
  padding-left: 8px;
  margin: 2px 0 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  cursor: pointer;
}
.fc-replyctx:hover { color: var(--fc-text-muted); }

/* Attachments */
.fc-att-wrap { display: flex; flex-wrap: wrap; gap: 6px; padding: 3px 0; }
.fc-att {
  display: block;
  max-width: 220px;
  max-height: 160px;
  border-radius: 6px;
  border: 1px solid var(--fc-border-soft);
  cursor: zoom-in;
  object-fit: cover;
}
.fc-att-pending {
  width: 84px;
  height: 64px;
  border-radius: 6px;
  border: 1px dashed var(--fc-border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fc-text-dim);
  font-size: 10px;
}

/* New divider (durable read cursor). */
.fc-new-divider {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0 4px;
  color: var(--fc-cyan-bright);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.fc-new-divider::before,
.fc-new-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(0, 200, 200, 0.35);
}

/* "New messages ↓" pill — shown when unpinned and something arrives. */
.fc-newpill {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 10px;
  z-index: 2;
  background: var(--fc-cyan);
  color: var(--fc-navy-deep);
  border: none;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 6px 13px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
}
.fc-newpill[hidden] { display: none; }
.fc-list-shell { position: relative; flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }

/* ---------------- Typing + composer ---------------- */

.fc-typing {
  min-height: 16px;
  font-size: 11px;
  color: var(--fc-text-dim);
  padding: 0 16px 2px;
  font-style: italic;
}

.fc-compose {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  /* 12px of real clearance at the bottom — the founder's "jammed down
     the bottom" was this row hard against the viewport edge. Consumers
     with reserved bottom chrome can add to it via --fc-bottom-inset
     (default 0, so no surface changes unless it opts in). */
  padding: 8px 12px calc(12px + env(safe-area-inset-bottom, 0px) + var(--fc-bottom-inset, 0px)) 12px;
  border-top: 1px solid var(--fc-border-soft);
}
/* CONSUMER-RESET GUARD (BL-318 polish, measured 2026-07-29).
   app/css/app.css loads AFTER this file and resets every authed-view
   textarea — `body.pga-ready textarea:not(.lg-textarea):not(.pga-input)`
   (specificity 0-3-2) — which outranked plain `.fc-input` (0-1-0). On the
   app that re-skinned the composer AND shrank its content box to 34px
   while the wrapping placeholder needed 52px: scrollHeight 52 >
   clientHeight 34, i.e. the input clipped its own first line at every
   viewport tested (1512x791, 1512x600, 1440x900, 390x844). Four classes
   (0-4-0) beat the host reset without reaching for !important, and the
   widget's controls keep the metrics the design contract chose. */
.fc-root .fc-panel .fc-compose .fc-input {
  flex: 1;
  resize: none;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--fc-border-soft);
  border-radius: var(--fc-radius);
  color: var(--fc-text);
  font-family: var(--fc-font);
  font-size: 13px;
  line-height: 1.45;
  padding: 8px 11px;
  min-height: 36px;
  max-height: 120px;
  transition: border-color 0.2s;
}
.fc-root .fc-panel .fc-compose .fc-input:focus { outline: none; border-color: rgba(0, 200, 200, 0.55); }
.fc-input::placeholder { color: var(--fc-text-dim); }

.fc-attach-btn,
.fc-send-btn {
  flex: 0 0 auto;
  height: 36px;
  border-radius: var(--fc-radius);
  border: 1px solid var(--fc-border-soft);
  background: rgba(255, 255, 255, 0.04);
  color: var(--fc-text-muted);
  cursor: pointer;
  font-family: var(--fc-font);
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.fc-attach-btn { width: 36px; font-size: 15px; }
.fc-attach-btn:hover { color: var(--fc-text); border-color: var(--fc-border); }
.fc-send-btn {
  padding: 0 15px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--fc-navy-deep);
  background: var(--fc-cyan);
  border-color: transparent;
}
.fc-send-btn:hover { background: var(--fc-cyan-bright); }
.fc-send-btn:disabled {
  background: rgba(255, 255, 255, 0.08);
  color: var(--fc-text-dim);
  cursor: not-allowed;
}
.fc-attach-btn:focus-visible,
.fc-send-btn:focus-visible { outline: 2px solid var(--fc-cyan); outline-offset: 1px; }

/* Pending attachment chip in the composer */
.fc-compose-att {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  font-size: 11px;
  color: var(--fc-text-muted);
}
/* An author `display` beats the UA sheet's `[hidden]{display:none}`
   regardless of specificity — without this the empty attachment row
   painted an 8px phantom strip above the composer at all times
   (measured on the app: hidden attribute present, display:flex). */
.fc-compose-att[hidden] { display: none; }
.fc-compose-att img { height: 34px; border-radius: 4px; border: 1px solid var(--fc-border-soft); }
.fc-compose-att button {
  background: none; border: none; color: var(--fc-text-dim);
  cursor: pointer; font-size: 13px; padding: 2px 4px;
}
.fc-compose-att button:hover { color: var(--fc-warn); }

/* Status line (rate-limit note, connection state, upload errors). */
.fc-note {
  min-height: 14px;
  font-size: 10.5px;
  color: var(--fc-text-dim);
  padding: 0 16px 6px;
}
.fc-note.is-warn { color: var(--fc-warn); }

/* Scrim behind the mobile sheet. */
.fc-scrim {
  position: fixed;
  inset: 0;
  background: rgba(3, 8, 16, 0.55);
  z-index: calc(var(--fc-z) - 1);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
@media (max-width: 639px) {
  .fc-root.is-open .fc-scrim { opacity: 1; pointer-events: auto; }
}
