/* Puna Ping — V1 component visual contract
 *
 * Lifted faithfully from `_handovers/2-prototypes/puna-ping-v1.html`.
 * Per surgical-changes discipline: do not deviate without `[SPEC-Q for 2]`.
 *
 * What this file owns:
 *   - The cursor dot (.ping-cursor-dot)
 *   - The drag rectangle (.ping-drag-rect)
 *   - The ping box (.ping-box, .ping-slots, .ping-slot, .ping-input-line)
 *   - Typewriter caret animation (.ping-slot.puna.is-thinking)
 *   - The body-level drag class (.ping-dragging) for text-selection suppression
 *
 * What this file does NOT own (surface-owned, integrate against existing):
 *   - The bottom adviser bar on /app (.adviser-bar selectors live in app/index.html)
 *   - The /tools wise adviser box (.fa-bar selectors live in tools/index.html)
 *   - The history rendering inside each persistent container (component injects rows; surface owns the container styles)
 *
 * Token dependencies (must be resolvable on the host page):
 *   --cyan, --cyan-bright, --cyan-dim, --white, --white-soft, --white-muted, --white-dim
 *   --navy, --navy-deep, --border, --border-light
 *   --font-body, --font-mono
 * These are defined in _components/design-tokens.css; the host page must load tokens first.
 */

body.ping-dragging {
  -webkit-user-select: none; user-select: none;
}
body.ping-dragging .ping-input-line input { -webkit-user-select: text; user-select: text; }

/* ============================================
   Cursor dot — appears at cursor tip whenever
   the cursor is over a pingable element. The
   "you can ping here" indicator.
   ============================================ */
.ping-cursor-dot {
  position: fixed; top: 0; left: 0;
  width: 6px; height: 6px;
  margin-left: 6px; margin-top: 6px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 8px rgba(0, 200, 200, 0.55);
  pointer-events: none;
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.ping-cursor-dot.is-on { opacity: 1; }
.ping-cursor-dot.is-dragging { opacity: 0.4; }
.ping-cursor-dot::after {
  content: ''; position: absolute; inset: -3px;
  border-radius: 50%;
  border: 1px solid rgba(0, 200, 200, 0.35);
  animation: ping-dot-pulse 2.2s ease-out infinite;
}
@keyframes ping-dot-pulse {
  0%   { transform: scale(0.8); opacity: 0.7; }
  100% { transform: scale(2.0); opacity: 0; }
}

/* ============================================
   Drag rectangle — light cyan box drawn while
   the user drags. Fades out on release.
   ============================================ */
.ping-drag-rect {
  position: fixed; top: 0; left: 0;
  border: 1px solid var(--cyan);
  background: rgba(0, 200, 200, 0.08);
  border-radius: 3px;
  pointer-events: none;
  z-index: 9990;
  display: none;
  transition: opacity 0.32s ease;
}
.ping-drag-rect.is-on { display: block; opacity: 1; }
.ping-drag-rect.is-fading { opacity: 0; }

/* ============================================
   Typewriter caret on the ping-slot body —
   blinking cyan bar that signals "thinking"
   ============================================ */
.ping-slot.puna.is-thinking .body::after {
  content: ''; display: inline-block;
  width: 2px; height: 0.95em; background: var(--cyan);
  margin-left: 2px; vertical-align: -1px;
  animation: ping-caret-blink 1s steps(1) infinite;
}
@keyframes ping-caret-blink {
  0%, 50%    { opacity: 1; }
  51%, 100%  { opacity: 0; }
}

/* ============================================
   Ping box — appears at cursor release point,
   stays as the conversation surface
   ============================================ */
.ping-box {
  position: fixed; top: 0; left: 0;
  width: 300px;
  background: rgba(11, 26, 46, 0.96);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--cyan-dim);
  border-radius: 6px;
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.42);
  z-index: 9995;
  display: none;
  flex-direction: column;
  pointer-events: auto;
  overflow: hidden;
}
.ping-box.is-on {
  display: flex;
  animation: ping-box-in 0.18s ease-out both;
}
@keyframes ping-box-in {
  from { opacity: 0; transform: translate3d(0, 4px, 0); }
  to   { opacity: 1; }
}

/* Two-slot conversational area — puna's latest message on top,
   user's latest message below. Both rewrite on each turn —
   no stacking. The full chat record lives in the persistent
   container (bar or box). */
.ping-slots {
  padding: 0.65rem 0.8rem 0.5rem;
}
.ping-slot {
  margin-bottom: 0.55rem;
  font-size: 0.84rem; line-height: 1.5;
}
.ping-slot:last-child { margin-bottom: 0; }
.ping-slot[hidden] { display: none; }
.ping-slot .who {
  font-family: var(--font-mono, 'JetBrains Mono', SFMono-Regular, monospace);
  font-size: 0.58rem; letter-spacing: 0.08em; text-transform: uppercase;
  display: block; margin-bottom: 0.1rem;
}
.ping-slot.you .who { color: var(--white-dim); }
.ping-slot.you .body { color: var(--white); }
.ping-slot.puna .who { color: var(--cyan); }
.ping-slot.puna .body { color: var(--white-soft); }
.ping-slot.puna.is-action .body { color: var(--white); }
.ping-slot.puna.is-action .body::before {
  content: '◉'; color: var(--cyan); margin-right: 0.3rem;
  font-size: 0.78em; vertical-align: 1px;
}
.ping-slot.puna.is-stale .body { color: var(--white-dim); font-style: italic; }
.ping-slot.puna.is-error .body { color: var(--white-dim); font-style: italic; }

/* Input line — Ask anything */
.ping-input-line {
  padding: 0.45rem 0.8rem 0.65rem;
  border-top: 1px solid var(--border);
}
.ping-input-line .who {
  font-family: var(--font-mono, 'JetBrains Mono', SFMono-Regular, monospace);
  font-size: 0.58rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--white-dim);
  margin-bottom: 0.1rem; display: block;
}
.ping-input-line input {
  width: 100%;
  background: transparent;
  border: 0; outline: 0; padding: 0;
  color: var(--white);
  font-family: var(--font-body, 'Inter', -apple-system, sans-serif);
  font-size: 0.84rem;
  line-height: 1.5;
  caret-color: var(--cyan);
}
.ping-input-line input::placeholder { color: var(--white-dim); }
.ping-input-line.is-disabled input { opacity: 0.5; cursor: not-allowed; }

/* Retry affordance for 5xx / network errors */
.ping-retry-row {
  padding: 0.4rem 0.8rem 0.55rem;
  display: none;
  border-top: 1px solid var(--border);
}
.ping-retry-row.is-on { display: flex; align-items: center; gap: 0.5rem; }
.ping-retry-btn {
  background: rgba(0, 200, 200, 0.10);
  border: 1px solid rgba(0, 200, 200, 0.40);
  color: var(--cyan);
  font-family: var(--font-mono, monospace);
  font-size: 0.6rem; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 3px;
  cursor: pointer;
}
.ping-retry-btn:hover {
  background: rgba(0, 200, 200, 0.18);
  color: var(--cyan-bright);
}

/* Esc hint — fades in on box hover */
.ping-esc-hint {
  position: absolute; bottom: 6px; right: 8px;
  font-family: var(--font-mono, 'JetBrains Mono', monospace);
  font-size: 0.56rem; letter-spacing: 0.06em;
  color: var(--white-dim);
  text-transform: uppercase;
  opacity: 0; transition: opacity 0.15s;
  pointer-events: none;
}
.ping-box:hover .ping-esc-hint { opacity: 0.7; }
.ping-esc-hint kbd {
  font-family: var(--font-mono, monospace);
  font-size: 0.55rem;
  padding: 0.02rem 0.28rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-light);
  border-radius: 2px;
  color: var(--white-dim);
}

/* ============================================
   Status line — rendered into the surface's
   [data-puna-ping-status] element. Widget
   writes "Drag to ping." / "In ping box now."
   here. Small mono eyebrow, dim so it doesn't
   compete with the surface's primary content.
   Empty by default (no text = no chrome).
   ============================================ */
.puna-ping-status-line {
  font-family: var(--font-mono, 'JetBrains Mono', SFMono-Regular, monospace);
  font-size: 0.6rem;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--white-dim);
  padding: 0 0 0.45rem;
  min-height: 0.85rem;
  line-height: 1.4;
}
.puna-ping-status-line:empty { padding: 0; }

/* ============================================
   History zone — rendered into the surface's
   [data-puna-ping-history] container by the
   widget. Component owns these visuals so
   bar (app) + box (tools) render history
   identically.
   ============================================ */
.puna-ping-history-empty,
.puna-ping-history-error {
  color: var(--white-dim);
  font-style: italic;
  font-size: 0.82rem;
  padding: 0.6rem 0;
}
.puna-ping-history-session {
  padding: 0.6rem 0;
  border-top: 1px dashed var(--border);
}
.puna-ping-history-session:first-child { border-top: none; padding-top: 0.3rem; }
.puna-ping-history-session-head {
  display: flex; gap: 0.8rem; align-items: baseline;
  margin-bottom: 0.3rem;
}
.puna-ping-history-session-ts {
  font-family: var(--font-mono, 'JetBrains Mono', monospace);
  font-size: 0.66rem; letter-spacing: 0.06em;
  color: var(--white-dim);
}
.puna-ping-history-turn {
  display: grid; grid-template-columns: 44px 1fr;
  gap: 0.6rem; align-items: baseline;
  padding: 0.15rem 0;
  font-size: 0.84rem; line-height: 1.5;
}
.puna-ping-history-turn .who {
  font-family: var(--font-mono, 'JetBrains Mono', monospace);
  font-size: 0.6rem; letter-spacing: 0.08em; text-transform: uppercase;
}
.puna-ping-history-turn.you .who { color: var(--white-dim); }
.puna-ping-history-turn.you .body { color: var(--white-soft); }
.puna-ping-history-turn.puna .who { color: var(--cyan); }
.puna-ping-history-turn.puna .body { color: var(--white-soft); }

/* Toast — used for sign-in / auth-failure feedback */
.ping-toast {
  position: fixed; top: 16px; left: 50%;
  transform: translateX(-50%);
  background: rgba(11, 26, 46, 0.96);
  border: 1px solid var(--cyan-dim);
  border-radius: 4px;
  padding: 10px 16px;
  font-size: 0.84rem;
  color: var(--white-soft);
  z-index: 10000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.ping-toast.is-on { opacity: 1; }
.ping-toast a { color: var(--cyan); text-decoration: none; border-bottom: 1px solid var(--cyan-dim); }
.ping-toast a:hover { color: var(--cyan-bright); }
