/* Rico aos Poucos — sistema de comentários (inline + finais) */

:root {
  --rap-c-bg: #ffffff;
  --rap-c-bg-alt: #f5f6f8;
  --rap-c-border: #e1e4e9;
  --rap-c-text: #1f2937;
  --rap-c-muted: #6b7280;
  --rap-c-accent: #2563eb;
  --rap-c-accent-soft: #dbeafe;
  --rap-c-warn: #b45309;
  --rap-c-err: #b91c1c;
  --rap-c-ok: #047857;
}
@media (prefers-color-scheme: dark) {
  :root {
    --rap-c-bg: #161b22;
    --rap-c-bg-alt: #0f1419;
    --rap-c-border: #2a313c;
    --rap-c-text: #e6edf3;
    --rap-c-muted: #8b949e;
    --rap-c-accent: #58a6ff;
    --rap-c-accent-soft: rgba(88,166,255,.15);
    --rap-c-warn: #f0c674;
    --rap-c-err: #ff8d85;
    --rap-c-ok: #6fdd84;
  }
}

/* ============ Highlight no texto âncora ============ */
.rap-c-anchor {
  background-color: var(--rap-c-accent-soft);
  border-bottom: 2px solid var(--rap-c-accent);
  padding: 0 2px;
  cursor: pointer;
  transition: background .15s;
}
.rap-c-anchor:hover { background-color: rgba(88,166,255,.3); }
.rap-c-anchor::after {
  content: attr(data-count);
  display: inline-block;
  background: var(--rap-c-accent);
  color: white;
  border-radius: 50%;
  font-size: 10px;
  width: 14px; height: 14px;
  text-align: center;
  line-height: 14px;
  margin-left: 3px;
  vertical-align: super;
  font-weight: 700;
}

/* ============ Tooltip de seleção ============ */
.rap-c-sel-tip {
  position: absolute;
  z-index: 9998;
  background: var(--rap-c-text);
  color: var(--rap-c-bg);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
  transform: translateX(-50%) translateY(-100%) translateY(-8px);
  display: flex;
  align-items: center;
  gap: 6px;
}
.rap-c-sel-tip::after {
  content: '';
  position: absolute;
  bottom: -6px; left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--rap-c-text);
  border-bottom-width: 0;
}

/* ============ Notas laterais (desktop ≥1300px) ============ */
/* z-index 40: acima do conteúdo do artigo mas ABAIXO do header fixo
   (.article-topbar-wrap usa z-index 50). */
.rap-c-margin-note {
  position: absolute;
  z-index: 40;
  background: var(--rap-c-bg);
  border: 1px solid var(--rap-c-border);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,.05);
  padding: 8px 10px;
  font-size: 12.5px;
  max-height: 380px;
  overflow-y: auto;
  transition: box-shadow .15s, border-color .15s;
}
.rap-c-margin-note:hover {
  border-color: var(--rap-c-accent);
  box-shadow: 0 4px 16px rgba(37,99,235,.12);
}
/* Setinha apontando pro trecho marcado (lado oposto da nota) */
.rap-c-margin-note::before,
.rap-c-margin-note::after {
  content: '';
  position: absolute;
  top: 14px;
  width: 0; height: 0;
  border: 7px solid transparent;
  pointer-events: none;
}
.rap-c-margin-note.side-right::before {
  left: -7px;
  border-right-color: var(--rap-c-border);
  border-left-width: 0;
}
.rap-c-margin-note.side-right::after {
  left: -6px;
  border-right-color: var(--rap-c-bg);
  border-left-width: 0;
}
.rap-c-margin-note.side-left::before {
  right: -7px;
  border-left-color: var(--rap-c-border);
  border-right-width: 0;
}
.rap-c-margin-note.side-left::after {
  right: -6px;
  border-left-color: var(--rap-c-bg);
  border-right-width: 0;
}

/* Modo "bare": uma única anotação sem replies — sem envelope.
   Mantém só a setinha + o card do comentário. */
.rap-c-margin-note.is-bare {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
  overflow: visible;
}
.rap-c-margin-note.is-bare:hover {
  border: none;
  box-shadow: none;
}
.rap-c-margin-note.is-bare .rap-c-margin-note-body .rap-c-card {
  margin-bottom: 0;
  background: var(--rap-c-bg);
  border: 1px solid var(--rap-c-border);
  box-shadow: 0 2px 6px rgba(0,0,0,.04);
}
.rap-c-margin-note.is-bare:hover .rap-c-margin-note-body .rap-c-card {
  border-color: var(--rap-c-accent);
  box-shadow: 0 4px 14px rgba(37,99,235,.1);
}
/* Em bare, a setinha precisa apontar pro card (não pro envelope inexistente) */
.rap-c-margin-note.is-bare.side-right::before { border-right-color: var(--rap-c-border); }
.rap-c-margin-note.is-bare.side-right::after  { border-right-color: var(--rap-c-bg-alt); }
.rap-c-margin-note.is-bare.side-left::before  { border-left-color: var(--rap-c-border); }
.rap-c-margin-note.is-bare.side-left::after   { border-left-color: var(--rap-c-bg-alt); }

.rap-c-margin-note-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--rap-c-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--rap-c-border);
}
.rap-c-margin-note-locate {
  background: none;
  border: none;
  color: var(--rap-c-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 0 4px;
  border-radius: 4px;
  line-height: 1;
}
.rap-c-margin-note-locate:hover { color: var(--rap-c-accent); background: var(--rap-c-accent-soft); }
.rap-c-margin-note-body .rap-c-card {
  font-size: 12.5px;
  padding: 8px 10px;
  margin-bottom: 6px;
}
.rap-c-margin-note-body .rap-c-replies {
  padding-left: 12px;
  margin: 4px 0 0 2px;
}
.rap-c-margin-note-flash {
  animation: rap-c-margin-flash 1s ease-out;
}
@keyframes rap-c-margin-flash {
  0%, 100% { box-shadow: 0 2px 8px rgba(0,0,0,.05); border-color: var(--rap-c-border); }
  40%      { box-shadow: 0 0 0 4px var(--rap-c-accent-soft); border-color: var(--rap-c-accent); }
}
.rap-c-anchor-flash {
  animation: rap-c-anchor-pulse 1s ease-out;
}
@keyframes rap-c-anchor-pulse {
  50% { background-color: rgba(255, 200, 0, .55); }
}
.rap-c-card-flash {
  animation: rap-c-card-pulse 1.4s ease-out;
}
@keyframes rap-c-card-pulse {
  0%, 100% { box-shadow: none; }
  30%      { box-shadow: 0 0 0 3px var(--rap-c-accent-soft); }
}

/* ============ Popover de anotação (drop-down ou lateral) ============ */
.rap-c-popover {
  position: absolute;
  z-index: 9995;
  background: var(--rap-c-bg);
  border: 1px solid var(--rap-c-border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0,0,0,.18), 0 2px 6px rgba(0,0,0,.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 280px;
  animation: rap-c-pop-in .15s ease-out;
}
@keyframes rap-c-pop-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.rap-c-popover-h {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--rap-c-border);
  background: var(--rap-c-bg-alt);
}
.rap-c-popover-ttl { font-size: 12px; font-weight: 700; color: var(--rap-c-text); text-transform: uppercase; letter-spacing: .03em; }
.rap-c-popover-body {
  padding: 10px 12px;
  overflow-y: auto;
  flex: 1;
}
/* Setinha indicativa */
.rap-c-popover.bottom::before,
.rap-c-popover.top::before,
.rap-c-popover.side-left::before,
.rap-c-popover.side-right::before {
  content: '';
  position: absolute;
  width: 0; height: 0;
  border: 7px solid transparent;
}
.rap-c-popover.bottom::before {
  top: -7px; left: 24px;
  border-bottom-color: var(--rap-c-bg-alt);
  border-top-width: 0;
}
.rap-c-popover.top::before {
  bottom: -7px; left: 24px;
  border-top-color: var(--rap-c-bg);
  border-bottom-width: 0;
}
.rap-c-popover.side-right::before {
  left: -7px; top: 14px;
  border-right-color: var(--rap-c-bg-alt);
  border-left-width: 0;
}
.rap-c-popover.side-left::before {
  right: -7px; top: 14px;
  border-left-color: var(--rap-c-bg);
  border-right-width: 0;
}

/* ============ Sidebar (desktop) ============ */
.rap-c-sidebar {
  position: fixed;
  top: 0; right: 0;
  width: 360px;
  height: 100vh;
  background: var(--rap-c-bg);
  border-left: 1px solid var(--rap-c-border);
  z-index: 9990;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .25s ease-out;
  box-shadow: -8px 0 24px rgba(0,0,0,.15);
}
.rap-c-sidebar.open { transform: translateX(0); }
.rap-c-sidebar-h {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--rap-c-border);
}
.rap-c-sidebar-h .ttl { font-weight: 700; font-size: 15px; color: var(--rap-c-text); }
.rap-c-close {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--rap-c-muted);
  cursor: pointer;
  line-height: 1;
}
.rap-c-sidebar-body { flex: 1; overflow-y: auto; padding: 14px 18px; }

@media (max-width: 768px) {
  .rap-c-sidebar { width: 100vw; }
}

/* ============ Card de comentário ============ */
.rap-c-card {
  background: var(--rap-c-bg-alt);
  border: 1px solid var(--rap-c-border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
  font-size: 13.5px;
  color: var(--rap-c-text);
}
.rap-c-card-h {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}
a.rap-c-card-name,
span.rap-c-card-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--rap-c-text);
  text-decoration: none;
}
a.rap-c-card-name:hover { color: var(--rap-c-accent); text-decoration: underline; }
.rap-c-card-time { font-size: 11px; color: var(--rap-c-muted); margin-left: auto; }

/* Ações no card (responder/editar/excluir) */
.rap-c-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px dashed var(--rap-c-border);
}
.rap-c-action-btn {
  background: none;
  border: none;
  color: var(--rap-c-muted);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.rap-c-action-btn:hover { color: var(--rap-c-accent); background: var(--rap-c-accent-soft); }
.rap-c-action-danger:hover { color: var(--rap-c-err); background: rgba(185,28,28,.08); }

/* Replies aninhados */
.rap-c-replies { padding-left: 22px; border-left: 2px solid var(--rap-c-border); margin: 6px 0 0 4px; }
.rap-c-replies:empty { display: none; }
.rap-c-reply { background: var(--rap-c-bg); }
.rap-c-reply-composer { margin-top: 8px; }
.rap-c-anchor-quote {
  border-left: 3px solid var(--rap-c-accent);
  padding: 4px 10px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--rap-c-muted);
  font-style: italic;
  background: rgba(88,166,255,.05);
  border-radius: 0 6px 6px 0;
}
.rap-c-card-body { line-height: 1.5; word-wrap: break-word; }
.rap-c-redacted {
  display: inline-block;
  background: rgba(180, 83, 9, .14);
  color: var(--rap-c-warn);
  border: 1px solid rgba(180, 83, 9, .35);
  padding: 0 8px;
  border-radius: 4px;
  font-size: 11.5px;
  font-style: italic;
  cursor: help;
  margin: 0 2px;
}
.rap-c-mod-note {
  margin-top: 8px;
  font-size: 11px;
  color: var(--rap-c-warn);
  font-style: italic;
  border-top: 1px dashed var(--rap-c-border);
  padding-top: 6px;
}

/* ============ Botão flutuante (abre sidebar) ============ */
.rap-c-fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  background: var(--rap-c-accent);
  color: white;
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(37,99,235,.35);
  z-index: 9989;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: inherit;
}
.rap-c-fab:hover { transform: translateY(-1px); box-shadow: 0 8px 22px rgba(37,99,235,.45); }
.rap-c-fab .badge {
  background: white;
  color: var(--rap-c-accent);
  border-radius: 999px;
  padding: 0 8px;
  font-size: 11px;
}

/* ============ Modal (compor / login) ============ */
.rap-c-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s;
}
.rap-c-modal.open { opacity: 1; pointer-events: auto; }
.rap-c-modal-card {
  background: var(--rap-c-bg);
  border-radius: 12px;
  width: min(520px, 100%);
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 16px 48px rgba(0,0,0,.4);
}
.rap-c-modal-h {
  padding: 16px 20px;
  border-bottom: 1px solid var(--rap-c-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.rap-c-modal-h h3 { margin: 0; font-size: 15px; color: var(--rap-c-text); }
.rap-c-modal-body { padding: 16px 20px; overflow-y: auto; color: var(--rap-c-text); }
.rap-c-modal-foot {
  padding: 12px 20px;
  border-top: 1px solid var(--rap-c-border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.rap-c-quote-preview {
  border-left: 3px solid var(--rap-c-accent);
  padding: 8px 12px;
  background: var(--rap-c-bg-alt);
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--rap-c-muted);
  font-style: italic;
  border-radius: 0 6px 6px 0;
}
.rap-c-textarea {
  width: 100%;
  min-height: 100px;
  background: var(--rap-c-bg-alt);
  border: 1px solid var(--rap-c-border);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  color: var(--rap-c-text);
  resize: vertical;
  box-sizing: border-box;
}
.rap-c-textarea:focus { outline: none; border-color: var(--rap-c-accent); }
.rap-c-counter {
  font-size: 11px;
  color: var(--rap-c-muted);
}
.rap-c-error {
  background: rgba(248,81,73,.1);
  color: var(--rap-c-err);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12.5px;
  margin-top: 8px;
}

.rap-c-btn {
  font-family: inherit;
  font-size: 13px;
  padding: 7px 16px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid var(--rap-c-border);
  background: var(--rap-c-bg-alt);
  color: var(--rap-c-text);
  font-weight: 500;
}
/* Botão primário usa a cor de texto como fundo (escuro no light theme,
   claro no dark theme) — mais sóbrio e com contraste forte. */
.rap-c-btn.primary {
  background: var(--rap-c-text);
  color: var(--rap-c-bg);
  border-color: var(--rap-c-text);
  font-weight: 600;
}
.rap-c-btn.primary:hover { filter: brightness(.92); }
.rap-c-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ============ Composer ============ */
.rap-c-composer { display: flex; flex-direction: column; gap: 6px; }
.rap-c-help {
  font-size: 12px;
  color: var(--rap-c-muted);
  background: var(--rap-c-bg-alt);
  padding: 8px 12px;
  border-radius: 6px;
  border-left: 3px solid var(--rap-c-accent);
}
.rap-c-input {
  width: 100%;
  background: var(--rap-c-bg-alt);
  border: 1px solid var(--rap-c-border);
  border-radius: 6px;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 14px;
  color: var(--rap-c-text);
  box-sizing: border-box;
}
.rap-c-input:focus { outline: none; border-color: var(--rap-c-accent); }

/* Login CTA — quando user não está logado via Google */
.rap-c-login-cta {
  background: linear-gradient(135deg, rgba(66,133,244,0.10), rgba(196,181,253,0.06));
  border: 1px solid rgba(66,133,244,0.30);
  border-radius: 10px;
  padding: 18px 20px;
  text-align: center;
}
.rap-c-login-cta-title {
  font-size: 16px;
  font-weight: 700;
  margin: 0 0 6px;
  color: var(--rap-c-text);
}
.rap-c-login-cta-sub {
  font-size: 13px;
  color: var(--rap-c-muted);
  margin: 0 0 14px;
  line-height: 1.45;
}
.rap-c-login-btn {
  display: inline-flex !important;
  align-items: center;
  gap: 8px;
  padding: 10px 18px !important;
  font-size: 14px;
  text-decoration: none;
}

/* Avatar do user logado dentro do composer */
.rap-c-identity-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--rap-c-border);
  flex-shrink: 0;
}

/* Identidade reconhecida — não é link, é card limpo */
.rap-c-identity-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--rap-c-bg-alt);
  border: 1px solid var(--rap-c-border);
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}
/* User logado via Google: foto à esquerda, texto colado nela. Sem space-between. */
.rap-c-identity-row.is-google {
  justify-content: flex-start;
}
.rap-c-identity-line.is-google {
  justify-content: flex-start;
}
.rap-c-identity-label {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
  font-size: 13px;
  color: var(--rap-c-text);
}
.rap-c-identity-prefix {
  font-size: 11px;
  color: var(--rap-c-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.rap-c-identity-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--rap-c-text);
}
.rap-c-identity-switch {
  font-size: 11.5px;
  padding: 5px 10px;
  white-space: nowrap;
}

.rap-c-status { font-size: 12px; color: var(--rap-c-muted); min-height: 16px; margin-top: 2px; }
.rap-c-avatar svg { display: block; }

/* Submit row: contador à esquerda, botões à direita, todos numa linha só */
.rap-c-submit-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}
.rap-c-submit-row .rap-c-counter {
  margin-right: auto;
  flex: 1 0 auto;
  text-align: left;
}
.rap-c-submit-row .rap-c-btn { flex: 0 0 auto; }

/* Variante compacta (replies em margin-notes / threads) — sem cards extras,
   sem help, sem anchor preview, identidade em uma linha só. */
.rap-c-composer.compact {
  gap: 4px;
  padding-top: 8px; /* respiro em relação ao botão "Responder" do card pai */
}
.rap-c-composer.compact .rap-c-submit-row { margin-top: 2px; }
.rap-c-composer.compact .rap-c-identity-line { margin-bottom: 2px; }

.rap-c-identity-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 2px 2px;
  font-size: 12.5px;
  line-height: 1.2;
}
.rap-c-identity-line-name {
  font-weight: 700;
  color: var(--rap-c-text);
}
.rap-c-link-mini {
  background: none;
  border: none;
  color: var(--rap-c-accent);
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
  padding: 0;
  text-transform: lowercase;
}
.rap-c-link-mini:hover { text-decoration: underline; }

/* ============ Bloco final do artigo ============ */
.rap-c-trailing {
  margin: 40px auto;
  max-width: 820px;
  padding: 24px 0;
  border-top: 1px solid var(--rap-c-border);
}
/* Variante usada em páginas que não têm anotação inline (ex.: FII):
   acompanha a largura do template de FII (1280px) com respiro lateral. */
.rap-c-trailing--wide {
  max-width: 1280px;
  padding: 24px 24px;
}
@media (max-width: 768px) {
  .rap-c-trailing--wide { padding: 20px 16px; }
}
.rap-c-trailing h3 {
  margin: 0 0 18px;
  font-size: 18px;
  color: var(--rap-c-text);
}
.rap-c-trailing-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--rap-c-border);
}
.rap-c-tab {
  background: none;
  border: none;
  padding: 8px 14px;
  font-family: inherit;
  font-size: 13px;
  color: var(--rap-c-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transform: translateY(1px);
  font-weight: 500;
}
.rap-c-tab.active { color: var(--rap-c-text); border-bottom-color: var(--rap-c-accent); }

.rap-c-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--rap-c-muted);
  font-size: 13.5px;
  font-style: italic;
}

.rap-c-toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--rap-c-text);
  color: var(--rap-c-bg);
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  z-index: 10001;
  box-shadow: 0 6px 18px rgba(0,0,0,.3);
  animation: rap-c-toast-in .25s ease-out;
}
.rap-c-toast.error { background: var(--rap-c-err); color: white; }
.rap-c-toast.success { background: var(--rap-c-ok); color: white; }
@keyframes rap-c-toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
