/* style_rag_editor.css | NMMI.ai | 2026-05-08
 * RAG smart-editor styles. Uses existing NMMI tokens so all four themes
 * (green-dark, green-light, teal-dark, teal-light) follow the active palette.
 *
 * Key NMMI tokens consumed:
 *   --accent, --accent-rgb, --accent-dim, --accent-soft, --accent-border,
 *   --accent-focus, --accent-glow, --bg-panel, --bg-surface, --muted-rgb
 */

/* ─── Editable surface (replaces #outputBox <textarea>) ────────────────── */
.rag-editor-surface {
  white-space: pre-wrap;
  word-wrap: break-word;
  outline: none;
}
.rag-editor-surface[data-placeholder]:empty::before,
.rag-editor-surface[data-placeholder]:has(p:only-child:empty)::before {
  content: attr(data-placeholder);
  color: rgba(var(--muted-rgb), 0.34);
  font-style: italic;
}
.rag-editor-surface p { margin: 0 0 0.75em; }
.rag-editor-surface p:last-child { margin-bottom: 0; }

/* ─── Tracked changes (ins/del) ────────────────────────────────────────── */
ins.tc {
  background: rgba(var(--accent-rgb), 0.16);
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: rgba(var(--accent-rgb), 0.55);
  cursor: pointer;
  border-radius: 2px;
  padding: 0 1px;
}
del.tc {
  background: rgba(220, 60, 60, 0.18);
  color: rgba(255, 180, 180, 0.95);
  text-decoration: line-through;
  cursor: pointer;
  border-radius: 2px;
  padding: 0 1px;
}
ins.tc[data-source="rag"], del.tc[data-source="rag"] {
  /* RAG-sourced edits get a subtle dotted underline cue */
  border-bottom: 1px dotted rgba(var(--accent-rgb), 0.65);
}
ins.tc:hover, del.tc:hover, ins.tc.hl, del.tc.hl {
  outline: 1px solid var(--accent-focus);
}

/* ─── Inline numbered citation superscript ─────────────────────────────── */
.rag-cite {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  background: rgba(var(--accent-rgb), 0.85);
  color: var(--bg-surface);
  border-radius: 50%;
  font-size: 9px;
  font-weight: 700;
  cursor: pointer;
  vertical-align: super;
  line-height: 1;
  margin: 0 1px;
  text-decoration: none;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.15s;
}
.rag-cite:hover { background: var(--accent-focus); transform: scale(1.08); }
.rag-cite.active {
  background: var(--accent);
  outline: 2px solid var(--accent-focus);
  color: var(--bg-surface);
}

/* ─── Hover tooltip ────────────────────────────────────────────────────── */
#ragTooltip {
  position: fixed;
  z-index: 9999;
  max-width: 340px;
  background: var(--bg-surface);
  color: var(--accent);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 0.78rem;
  line-height: 1.5;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.18s, transform 0.18s;
  border: 1px solid var(--accent-border);
}
#ragTooltip.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
#ragTooltip .tip-label {
  font-size: 0.6rem;
  color: rgba(var(--accent-rgb), 0.6);
  text-transform: uppercase;
  letter-spacing: 0.7px;
  margin-bottom: 5px;
  font-weight: 600;
}
#ragTooltip .tip-insight { color: var(--accent); margin-bottom: 6px; }
#ragTooltip .tip-src { font-size: 0.72rem; color: rgba(var(--muted-rgb), 0.7); font-style: italic; }
#ragTooltip .tip-cta {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.7rem;
  color: var(--accent-focus);
  cursor: pointer;
  text-decoration: underline;
}

/* ─── SVG connector (citation ↔ chat card) ─────────────────────────────── */
#connSvg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 6;
}

/* ─── REVIEW pane: badge + analyse buttons ─────────────────────────────── */
.review-panel .panel-head { position: relative; }
.rp-badge {
  margin-left: 8px;
  background: rgba(var(--accent-rgb), 0.22);
  color: var(--accent);
  border-radius: 9px;
  padding: 1px 7px;
  font-size: 0.66rem;
  font-weight: 700;
  min-width: 18px;
  text-align: center;
}
#ragActions {
  margin-left: auto;
  display: flex;
  gap: 4px;
}
.rag-btn,
.rag-btn-ghost {
  background: rgba(var(--accent-rgb), 0.1);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.7rem;
  transition: background 0.15s, border-color 0.15s;
}
.rag-btn:hover { background: rgba(var(--accent-rgb), 0.2); border-color: var(--accent-soft); }
.rag-btn.running { animation: rag-pulse 1s infinite; }
@keyframes rag-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
.rag-btn-ghost:hover { background: rgba(220, 60, 60, 0.14); border-color: rgba(220, 60, 60, 0.4); }

/* ─── Bulk action tray inside Commentary pane ──────────────────────────── */
#rpBulkActions {
  display: flex;
  gap: 5px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--accent-border);
  flex-shrink: 0;
}
#rpBulkActions button {
  flex: 1;
  padding: 4px 6px;
  font-size: 0.7rem;
  border-radius: 4px;
  border: 1px solid var(--accent-border);
  cursor: pointer;
  font-weight: 600;
  background: rgba(var(--accent-rgb), 0.06);
  color: var(--accent);
  transition: background 0.15s;
}
#rpBulkActions .bulk-acc:hover { background: rgba(40, 180, 100, 0.18); }
#rpBulkActions .bulk-rej:hover { background: rgba(220, 60, 60, 0.18); }

/* ─── Chat-style messages in the Commentary pane ───────────────────────── */
.commentary-list .chat-msg {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  animation: rag-fade-up 0.25s ease;
}
@keyframes rag-fade-up {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.chat-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  margin-top: 2px;
  background: rgba(var(--accent-rgb), 0.18);
  color: var(--accent);
}
.chat-body { flex: 1; max-width: calc(100% - 36px); }
.chat-name {
  font-size: 0.6rem;
  color: rgba(var(--muted-rgb), 0.55);
  margin-bottom: 3px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.chat-bubble {
  background: var(--bg-panel);
  border: 1px solid var(--accent-border);
  border-left: 3px solid var(--accent-dim);
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 0.76rem;
  line-height: 1.55;
  color: rgba(var(--muted-rgb), 0.88);
  word-break: break-word;
}
.chat-time { font-size: 0.62rem; color: rgba(var(--muted-rgb), 0.4); margin-top: 3px; text-align: right; }
.chat-msg.active .chat-bubble { border-color: var(--accent-focus); box-shadow: 0 0 6px rgba(var(--accent-rgb), 0.18); }

/* TC-specific colouring */
.msg-tc.insert-msg .chat-avatar { background: rgba(40, 180, 100, 0.22); color: rgba(40, 200, 130, 0.95); }
.msg-tc.insert-msg .chat-bubble { border-left-color: rgba(40, 180, 100, 0.5); }
.msg-tc.delete-msg .chat-avatar { background: rgba(220, 60, 60, 0.22); color: rgba(255, 140, 140, 0.95); }
.msg-tc.delete-msg .chat-bubble { border-left-color: rgba(220, 60, 60, 0.5); }

.tc-changed-text {
  display: block;
  margin: 4px 0;
  padding: 3px 7px;
  background: rgba(var(--accent-rgb), 0.06);
  border-radius: 3px;
  max-height: 54px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-style: italic;
  font-size: 0.72rem;
  color: var(--accent-focus);
}
.tc-btns, .rag-btns { display: flex; gap: 5px; margin-top: 6px; }
.tc-btns button, .rag-btns button {
  flex: 1;
  padding: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
}
.btn-acc, .btn-rag-acc { background: rgba(40, 180, 100, 0.65); color: #fff; }
.btn-rej, .btn-rag-rej { background: rgba(220, 60, 60, 0.55); color: #fff; }
.btn-acc:hover, .btn-rag-acc:hover { background: rgba(40, 180, 100, 0.85); }
.btn-rej:hover, .btn-rag-rej:hover { background: rgba(220, 60, 60, 0.75); }
.btn-rag-acc[disabled], .btn-rag-rej[disabled] { opacity: 0.45; cursor: not-allowed; }

/* RAG insight card */
.msg-rag .chat-avatar { background: rgba(var(--accent-rgb), 0.25); color: var(--accent-focus); }
.msg-rag .chat-bubble { border-left-color: var(--accent-focus); }
.rag-row { display: flex; align-items: flex-start; gap: 6px; }
.rag-insight-num {
  display: inline-block;
  background: rgba(var(--accent-rgb), 0.85);
  color: var(--bg-surface);
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 0.62rem;
  font-weight: 700;
  text-align: center;
  line-height: 18px;
  flex-shrink: 0;
}
.rag-insight-text { font-size: 0.78rem; line-height: 1.55; color: rgba(var(--muted-rgb), 0.92); }
.rag-source-pill {
  display: inline-block;
  margin-top: 5px;
  background: rgba(var(--accent-rgb), 0.14);
  color: var(--accent-focus);
  border-radius: 9px;
  padding: 1px 8px;
  font-size: 0.64rem;
  font-weight: 600;
}
.rag-suggestion {
  margin-top: 6px;
  padding: 5px 8px;
  background: var(--bg-panel);
  border: 1px dashed var(--accent-border);
  border-radius: 4px;
  font-size: 0.74rem;
  color: rgba(var(--muted-rgb), 0.85);
}
.rag-suggestion strong {
  display: block;
  font-size: 0.6rem;
  color: var(--accent-focus);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
  font-weight: 700;
}
.msg-rag.rag-accepted { opacity: 0.6; pointer-events: none; }
.msg-rag.rag-accepted::after { content: ' ✓ Accepted'; color: rgba(40, 180, 100, 0.95); font-size: 0.65rem; font-weight: 700; }
.msg-rag.rag-rejected { opacity: 0.45; pointer-events: none; }
.msg-rag.rag-rejected::after { content: ' ✗ Dismissed'; color: rgba(var(--muted-rgb), 0.55); font-size: 0.65rem; font-weight: 700; }

/* Loading + info bubbles */
.msg-loading .chat-bubble { font-style: italic; color: rgba(var(--muted-rgb), 0.6); }
.msg-info .chat-avatar { background: rgba(var(--muted-rgb), 0.25); color: rgba(var(--muted-rgb), 0.85); }
.msg-info .chat-bubble { border-left-color: rgba(var(--muted-rgb), 0.4); font-style: italic; }

/* Source tag pill in tracked-change card title */
.src-tag {
  font-size: 0.55rem;
  padding: 1px 5px;
  border-radius: 7px;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.src-tag.rag   { background: rgba(var(--accent-rgb), 0.22); color: var(--accent-focus); }
.src-tag.human { background: rgba(var(--muted-rgb), 0.18); color: rgba(var(--muted-rgb), 0.75); }
