/**
 * FCA Multi-Reactions — Picker + Summary + Modal Styling
 */

/* ============================================================
   HIDE FC'S NATIVE REACTION DISPLAY
   We render our own summary and own the click target, so FC's
   native avatar stack + "who reacted" popover must step aside.
   Hidden via a root class set by the injector at init.
   ============================================================ */

/* Feed: the native reactions count (avatars + el-popover trigger). */
html.fcamr-reactions-on .fcom_feed_footer_meta .fcom_reactions_count.feed_reaction_meta {
  display: none !important;
}

/* Comments: hide FC's native like button in the reply row (we render our own
   picker inline). We target the .reply_btn span that wraps FC's native react
   so we don't hit our own .fcamr-comment-picker-host (which also carries
   fcom_comments_react classes but is a direct child of .reply_box). */
html.fcamr-comment-reactions-on .reply_box .reply_btn:has(> .fcom_comments_react) {
  display: none !important;
}

/* Lay the reply row out as a single line so our picker sits inline with the
   "Reply" link and the summary can sit at the end. */
html.fcamr-comment-reactions-on .reply_box {
  display: flex;
  align-items: center;
  gap: 12px;
}

html.fcamr-comment-reactions-on .reply_box > .fcamr-comment-summary-host {
  margin-left: auto;
}

/* Lay the footer meta out as a single row so our summary sits inline,
   side by side with the comment counter (FC renders it display:block,
   which would stack our summary above the comment-count <ul>). */
html.fcamr-reactions-on .fcom_feed_footer_meta {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* Our owned summary sits first in the footer-meta row. */
html.fcamr-reactions-on .fcom_feed_footer_meta > .fcamr-emoji-summary {
  order: -1;
}

/* Share the comment counter's type styling so the two read as a set. */
html.fcamr-reactions-on .fcamr-emoji-summary .fcamr-summary-count {
  font-size: 13px;
  font-weight: 500;
  color: var(--fcom-secondary-text, #65676b);
}

/* Fallback when the emoji SVG fails to load — show the unicode glyph. */
.fcamr-emoji-text {
  font-style: normal;
  line-height: 1;
}

/* ============================================================
   REACTION PICKER
   ============================================================ */

/* Host element: the original FC reaction li/div with our picker injected */
[data-fcamr-rxn] {
  position: relative;
  /* Suppress the long-press "save image / open link" callout on mobile. */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* Our emoji images are decorative — never let a long-press grab them, and
   route taps to the button/host behind them. */
.fcamr-rxn-emoji-overlay img,
.fcamr-rxn-dropdown-emoji-img,
.fcamr-summary-emoji {
  pointer-events: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  user-select: none;
}

.fcamr-rxn-dropdown {
  -webkit-touch-callout: none;
  user-select: none;
}

/* Emoji overlay on FC's reaction button (SVG flat style) */
.fcamr-rxn-emoji-overlay {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  transition: transform 0.15s;
}

.fcamr-rxn-btn-img {
  width: 20px;
  height: 20px;
}

/* Smaller emoji for comment reactions */
.fcamr-rxn-comment .fcamr-rxn-btn-img {
  width: 16px;
  height: 16px;
}

/* Grey transparent default thumb for unreacted buttons */
.fcamr-rxn-btn-img.fcamr-rxn-default {
  opacity: 0.4;
  filter: grayscale(1);
}

[data-fcamr-rxn]:hover .fcamr-rxn-emoji-overlay {
  transform: scale(1.2);
}

/* Dropdown picker — uses position:fixed to escape overflow:auto/hidden ancestors */
.fcamr-rxn-dropdown {
  position: fixed;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px;
  /* Cap the width so many reactions wrap into rows instead of one long row
     that runs off screen. The JS clamps the final position to the viewport. */
  max-width: min(320px, calc(100vw - 16px));
  padding: 4px 6px;
  background: var(--fcom-primary-bg, #fff);
  border: 1px solid var(--fcom-primary-border, #e5e7eb);
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
  z-index: 99999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
}

.fcamr-rxn-dropdown.fcamr-rxn-dropdown-visible {
  opacity: 1;
  pointer-events: auto;
}

/* Individual emoji in the dropdown */
.fcamr-rxn-dropdown-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: transform 0.12s, background 0.12s;
  padding: 0;
}

.fcamr-rxn-dropdown-item:hover {
  background: var(--fcom-active-bg, rgba(0, 0, 0, 0.06));
  transform: scale(1.25);
}

.fcamr-rxn-dropdown-emoji {
  font-size: 18px;
  line-height: 1;
}

.fcamr-rxn-dropdown-emoji-img {
  width: 22px;
  height: 22px;
}

/* Comment reaction bar — sits below comment body */
.fcamr-comment-reaction-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0 2px;
  margin-top: 4px;
  min-height: 24px;
}

.fcamr-comment-picker-host {
  display: inline-flex;
  align-items: center;
  position: relative;
}

.fcamr-comment-summary-host {
  display: inline-flex;
  align-items: center;
  margin-left: auto;
}

.fcamr-comment-summary-host .fcamr-emoji-summary {
  gap: 0;
}

.fcamr-comment-summary-host .fcamr-summary-emoji {
  width: 15px;
  height: 15px;
}

.fcamr-comment-summary-host .fcamr-summary-count {
  font-size: 12px !important;
}

/* Dark mode — picker */
html.dark .fcamr-rxn-dropdown {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}


/* ============================================================
   EMOJI SUMMARY (overlapping emoji stack on reaction meta)
   ============================================================ */

.fcamr-emoji-summary {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  position: relative;
  z-index: 1;
  gap: 0;
  white-space: nowrap;
}

.fcamr-emoji-summary:hover {
  opacity: 0.85;
}

.fcamr-emoji-stack {
  display: inline-flex;
  align-items: center;
}

.fcamr-summary-emoji {
  --fcamr-stroke: 2px;
  width: 18px;
  height: 18px;
  display: inline-block;
  position: relative;
  filter:
    drop-shadow(var(--fcamr-stroke) 0 0 var(--fcom-primary-bg, #fff))
    drop-shadow(calc(var(--fcamr-stroke) * -1) 0 0 var(--fcom-primary-bg, #fff))
    drop-shadow(0 var(--fcamr-stroke) 0 var(--fcom-primary-bg, #fff))
    drop-shadow(0 calc(var(--fcamr-stroke) * -1) 0 var(--fcom-primary-bg, #fff));
}

.fcamr-summary-emoji-text {
  font-size: 14px;
  line-height: 18px;
  text-align: center;
}

.fcamr-emoji-summary .fcamr-summary-count {
  margin-left: 4px !important;
  color: var(--fcom-secondary-text, #65676b);
  font-size: 13px !important;
  white-space: nowrap;
  font-weight: 600 !important;
}

html.dark .fcamr-emoji-summary .fcamr-summary-count {
  color: var(--fcom-secondary-text, #b0b8c1);
}

/* Real-time count bump animation */
@keyframes fcamr-count-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.3); color: var(--fcom-text-link, #216FDB); }
  100% { transform: scale(1); }
}

.fcamr-count-bump {
  display: inline-block;
  animation: fcamr-count-bump 0.4s ease;
}


/* ============================================================
   BREAKDOWN MODAL
   ============================================================ */

/* Overlay */
.fcamr-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 99998;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Modal container */
.fcamr-modal {
  background: var(--fcom-primary-bg, #fff);
  width: 500px;
  max-width: 90vw;
  max-height: 80vh;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  border: 1px solid var(--fcom-primary-border, #DADDE1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 99999;
}

/* Header */
.fcamr-modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--fcom-primary-border, #DADDE1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.fcamr-modal-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--fcom-primary-text, #050505);
}

.fcamr-modal-close {
  background: none;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  color: var(--fcom-secondary-text, #65676b);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.fcamr-modal-close:hover {
  background: var(--fcom-active-bg, #f0f2f5);
}

/* Body */
.fcamr-modal-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Tabs */
.fcamr-tabs {
  display: flex;
  gap: 4px;
  padding: 0 16px;
  overflow-x: auto;
  border-bottom: 1px solid var(--fcom-primary-border, #DADDE1);
  flex-shrink: 0;
}

.fcamr-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 14px;
  border: none;
  background: none;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 500;
  color: var(--fcom-secondary-text, #65676b);
  transition: all 0.15s ease;
}

.fcamr-tab:hover {
  background: var(--fcom-active-bg, #f0f2f5);
  border-radius: 6px 6px 0 0;
}

.fcamr-tab.active {
  color: var(--fcom-text-link, #216FDB);
  border-bottom-color: var(--fcom-text-link, #216FDB);
}

.fcamr-tab-emoji {
  width: 18px;
  height: 18px;
  vertical-align: middle;
}

.fcamr-tab-emoji-text {
  font-size: 16px;
  line-height: 1;
}

/* Panels */
.fcamr-panels {
  flex: 1;
  overflow-y: auto;
}

.fcamr-panel {
  display: none;
}

.fcamr-panel.active {
  display: block;
}

/* User list — uses FC-native avatar classes */
.fcamr-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  text-decoration: none;
  color: inherit;
  transition: background 0.15s ease;
}

.fcamr-user:hover {
  background: var(--fcom-active-bg, #f0f2f5);
}

.fcamr-user-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.fcamr-user-avatar-wrap .fcom_user_avatar {
  width: 40px;
  height: 40px;
}

.fcamr-user-avatar-wrap .fcom_user_avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.fcamr-user-reaction {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 20px;
  height: 20px;
  background: var(--fcom-primary-bg, #fff);
  border: 2px solid var(--fcom-primary-bg, #fff);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.fcamr-user-reaction img {
  width: 14px;
  height: 14px;
}

.fcamr-user-reaction span {
  font-size: 12px;
  line-height: 1;
}

.fcamr-user-name {
  font-weight: 500;
  font-size: 14px;
  color: var(--fcom-primary-text, #050505);
}

/* Modal states */
.fcamr-modal-loading,
.fcamr-modal-error,
.fcamr-modal-empty {
  padding: 32px;
  text-align: center;
  color: var(--fcom-secondary-text, #65676b);
  font-size: 14px;
}

.fcamr-modal-error {
  color: #ef4444;
}

.fcamr-modal-more {
  padding: 12px 20px;
  text-align: center;
  color: var(--fcom-secondary-text, #65676b);
  font-size: 13px;
  font-style: italic;
}

/* Dark mode — modal */
html.dark .fcamr-modal {
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

html.dark .fcamr-modal-overlay {
  background: rgba(0, 0, 0, 0.6);
}

html.dark .fcamr-summary-emoji {
  filter:
    drop-shadow(var(--fcamr-stroke) 0 0 var(--fcom-primary-bg, #1a1a1a))
    drop-shadow(calc(var(--fcamr-stroke) * -1) 0 0 var(--fcom-primary-bg, #1a1a1a))
    drop-shadow(0 var(--fcamr-stroke) 0 var(--fcom-primary-bg, #1a1a1a))
    drop-shadow(0 calc(var(--fcamr-stroke) * -1) 0 var(--fcom-primary-bg, #1a1a1a));
}
