/**
 * FCA Custom Menus — Mobile bar + pull-out tray
 *
 * A larger, nicer replacement for FluentCommunity's native mobile bottom menu,
 * with a bottom pull-out tray that hosts Search / Chat / Sidebar panels. Panels
 * keep their own state so you can slide the tray back and keep browsing where
 * you were. Everything here is mobile-only (<= 768px).
 *
 * Theme-aware: consumes FC's own CSS vars; also styles FC's dark selectors.
 */

.fca-cm {
  --fca-cm-bar-h: 64px;
  --fca-cm-bg: var(--fcom-primary-bg, #fff);
  --fca-cm-text: var(--fcom-menu-text, var(--fcom-primary-text, #050505));
  --fca-cm-muted: var(--fcom-text-off, #8a8d91);
  --fca-cm-border: var(--fcom-primary-border, #e4e6eb);
  --fca-cm-active: var(--fcom-text-link, #1877f2);
  --fca-cm-hover: var(--fcom-secondary-bg, #f0f2f5);
  /* Sits with FC's own mobile menu (1001) and BELOW Element Plus overlays
     (2000+), so post drawers, dialogs and pickers cover the bar instead of
     the bar covering their composer / action buttons. */
  --fca-cm-z: 1000;

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.fcom_dark_mode .fca-cm,
[data-theme="dark"] .fca-cm {
  --fca-cm-bg: var(--fcom-primary-bg, #1c1e21);
  --fca-cm-border: var(--fcom-primary-border, #303339);
  --fca-cm-hover: var(--fcom-secondary-bg, #26282c);
}

/* ── Bottom bar ─────────────────────────────────────────────────────────── */
.fca-cm-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  /* Above the tray: the bar must stay visible & tappable while the tray is
     open, so tapping the same icon closes it (toggle) and other icons switch. */
  z-index: calc(var(--fca-cm-z) + 5);
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  height: calc(var(--fca-cm-bar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--fca-cm-bg);
  border-top: 1px solid var(--fca-cm-border);
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.06);
}

.fca-cm-bar-item {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  padding: 6px 4px;
  border: none;
  background: none;
  color: var(--fca-cm-text);
  text-decoration: none;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.fca-cm-bar-item .fca-cm-ico {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  line-height: 1;
}

.fca-cm-bar-item .fca-cm-ico svg {
  width: 24px;
  height: 24px;
  display: block;
}

.fca-cm-bar-item .fca-cm-lbl {
  font-size: 10px;
  font-weight: 500;
  line-height: 1;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fca-cm-bar-item:active { opacity: 0.6; }
.fca-cm-bar-item.is-active { color: var(--fca-cm-active); }

/* Unread badge (chat) */
.fca-cm-badge {
  position: absolute;
  top: 4px;
  left: calc(50% + 6px);
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  display: none;
}
.fca-cm-badge.is-visible { display: block; }

/* ── Scrim (transparent — no dark backdrop, per spec — just catches taps) ── */
.fca-cm-scrim {
  position: fixed;
  inset: 0;
  z-index: calc(var(--fca-cm-z) + 3);
  background: transparent;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}
.fca-cm-scrim.is-open { opacity: 1; visibility: visible; }

/* ── Pull-out tray ─────────────────────────────────────────────────────── */
.fca-cm-tray {
  position: fixed;
  left: 0;
  right: 0;
  /* Sit ABOVE the bottom bar (not over it) so the bar stays tappable —
     tapping the open panel's icon again closes the tray. */
  bottom: calc(var(--fca-cm-bar-h) + env(safe-area-inset-bottom, 0px));
  z-index: calc(var(--fca-cm-z) + 4);
  display: flex;
  flex-direction: column;
  height: calc(85vh - var(--fca-cm-bar-h));
  max-height: calc(85vh - var(--fca-cm-bar-h));
  background: var(--fca-cm-bg);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.18);
  transform: translateY(calc(100% + var(--fca-cm-bar-h) + env(safe-area-inset-bottom, 0px)));
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
  overflow: hidden;
}
.fca-cm[data-animation="fade"] .fca-cm-tray {
  transform: translateY(24px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease, transform 0.25s ease;
}
.fca-cm-tray.is-open { transform: translateY(0); }
.fca-cm[data-animation="fade"] .fca-cm-tray.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* Drag grip */
.fca-cm-grip {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  padding: 10px 0 4px;
  cursor: grab;
  touch-action: none;
}
.fca-cm-grip span {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--fca-cm-border);
}

/* Header */
.fca-cm-tray-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 16px 10px;
  border-bottom: 1px solid var(--fca-cm-border);
}
.fca-cm-tray-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--fca-cm-text);
}
.fca-cm-tray-close {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--fca-cm-hover);
  color: var(--fca-cm-text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Body / panel host — this is the contract host consumers append into */
.fca-pwa-sidebar-content {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.fca-cm-slot {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.fca-cm-slot.active { display: flex; }

/* Generic scroll region inside a slot */
.fca-cm-slot > .fca-cm-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Bottom tab strip */
.fca-cm-tabs {
  flex-shrink: 0;
  display: flex;
  border-top: 1px solid var(--fca-cm-border);
  background: var(--fca-cm-bg);
}
.fca-cm-tab {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 4px;
  border: none;
  background: none;
  color: var(--fca-cm-muted);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
}
.fca-cm-tab .fca-cm-ico { width: 22px; height: 22px; font-size: 20px; }
.fca-cm-tab .fca-cm-ico svg { width: 22px; height: 22px; }
.fca-cm-tab.active { color: var(--fca-cm-active); }

/* ── Sidebar/nav clone + custom html panels ────────────────────────────── */
.fca-cm-navlist { padding: 12px; }
.fca-cm-navlist a,
.fca-cm-navlist .fca-cm-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 10px;
  color: var(--fca-cm-text);
  text-decoration: none;
  font-size: 15px;
}
.fca-cm-navlist a:active,
.fca-cm-navlist .fca-cm-nav-item:active { background: var(--fca-cm-hover); }
.fca-cm-custom-html { padding: 16px; color: var(--fca-cm-text); }

/* ── Chat panel ────────────────────────────────────────────────────────── */
.fca-cm-chat { display: flex; flex-direction: column; height: 100%; }
.fca-cm-chat-empty,
.fca-cm-chat-loading {
  padding: 32px 16px;
  text-align: center;
  color: var(--fca-cm-muted);
  font-size: 14px;
}
.fca-cm-thread {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  border-bottom: 1px solid var(--fca-cm-border);
  color: var(--fca-cm-text);
  font: inherit;
}
.fca-cm-thread:active { background: var(--fca-cm-hover); }
.fca-cm-thread-avatar {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 50%;
  object-fit: cover;
  background: var(--fca-cm-hover);
}
.fca-cm-thread-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.fca-cm-thread-name {
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fca-cm-thread-preview {
  font-size: 13px;
  color: var(--fca-cm-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fca-cm-thread.is-unread .fca-cm-thread-name { font-weight: 700; }
.fca-cm-thread.is-unread .fca-cm-thread-preview { color: var(--fca-cm-text); }
.fca-cm-thread-dot {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--fca-cm-active);
  visibility: hidden;
}
.fca-cm-thread.is-unread .fca-cm-thread-dot { visibility: visible; }

/* Conversation view */
.fca-cm-convo { display: flex; flex-direction: column; height: 100%; }
.fca-cm-convo-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--fca-cm-border);
}
.fca-cm-convo-back {
  border: none;
  background: none;
  color: var(--fca-cm-active);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
}
.fca-cm-convo-title { font-size: 15px; font-weight: 600; color: var(--fca-cm-text); }
.fca-cm-convo-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.fca-cm-msg {
  max-width: 78%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.35;
  word-wrap: break-word;
}
.fca-cm-msg.is-mine {
  align-self: flex-end;
  background: var(--fca-cm-active);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.fca-cm-msg.is-theirs {
  align-self: flex-start;
  background: var(--fca-cm-hover);
  color: var(--fca-cm-text);
  border-bottom-left-radius: 4px;
}
.fca-cm-convo-foot {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--fca-cm-border);
}
.fca-cm-convo-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--fca-cm-border);
  border-radius: 20px;
  background: var(--fca-cm-bg);
  color: var(--fca-cm-text);
  font: inherit;
  font-size: 14px;
}
.fca-cm-convo-send {
  flex-shrink: 0;
  padding: 0 16px;
  border: none;
  border-radius: 20px;
  background: var(--fca-cm-active);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
.fca-cm-convo-send:disabled { opacity: 0.5; cursor: default; }

/* Message meta / rich content */
.fca-cm-msg-group { display: flex; flex-direction: column; gap: 2px; max-width: 82%; }
.fca-cm-msg-group.is-mine { align-self: flex-end; align-items: flex-end; }
.fca-cm-msg-group.is-theirs { align-self: flex-start; align-items: flex-start; }
.fca-cm-msg-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--fca-cm-muted);
  padding: 0 6px;
}
.fca-cm-msg-group .fca-cm-msg { max-width: 100%; }
.fca-cm-msg-time {
  font-size: 10px;
  color: var(--fca-cm-muted);
  padding: 0 6px;
}
.fca-cm-msg .chat_text { white-space: pre-wrap; }
.fca-cm-msg .chat_text p { margin: 0; }
.fca-cm-msg .chat_text a { color: inherit; text-decoration: underline; }
.fca-cm-msg .chat_medias { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.fca-cm-msg .chat_media img { max-width: 100%; max-height: 220px; border-radius: 10px; display: block; }
.fca-cm-msg .chat_media_overlay { display: none; }
.fca-cm-msg.is-pending { opacity: 0.6; }
.fca-cm-msg.is-failed { outline: 1px solid #ef4444; }
.fca-cm-load-more {
  align-self: center;
  margin: 0 0 4px;
  padding: 6px 14px;
  border: 1px solid var(--fca-cm-border);
  border-radius: 16px;
  background: var(--fca-cm-bg);
  color: var(--fca-cm-active);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.fca-cm-chat-error {
  padding: 6px 12px;
  font-size: 12px;
  color: #ef4444;
  text-align: center;
}
.fca-cm-convo-input { resize: none; max-height: 96px; line-height: 1.35; }
.fca-cm-thread-time {
  font-size: 11px;
  color: var(--fca-cm-muted);
  flex-shrink: 0;
  margin-left: auto;
  padding-left: 6px;
}
.fca-cm-thread-avatar { display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--fca-cm-muted); font-size: 16px; overflow: hidden; }
.fca-cm-thread-avatar img, .fca-cm-thread-avatar svg { width: 100%; height: 100%; object-fit: cover; }
.fca-cm-thread-section {
  padding: 10px 16px 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--fca-cm-muted);
}

/* ── Alerts panel ──────────────────────────────────────────────────────── */
.fca-cm-alerts { display: flex; flex-direction: column; height: 100%; }
.fca-cm-alerts-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--fca-cm-muted);
  border-bottom: 1px solid var(--fca-cm-border);
}
.fca-cm-alerts-readall {
  border: none;
  background: none;
  color: var(--fca-cm-active);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
}
.fca-cm-alert {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  border-bottom: 1px solid var(--fca-cm-border);
  color: var(--fca-cm-text);
  font: inherit;
}
.fca-cm-alert:active { background: var(--fca-cm-hover); }
.fca-cm-alert.is-unread { background: color-mix(in srgb, var(--fca-cm-active) 6%, transparent); }
.fca-cm-alert .fca-cm-thread-avatar { width: 40px; height: 40px; padding: 8px; box-sizing: border-box; }
.fca-cm-alert-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.fca-cm-alert-text { font-size: 14px; line-height: 1.35; }
.fca-cm-alert-text b, .fca-cm-alert-text strong { font-weight: 600; }
.fca-cm-alert-time { font-size: 11px; color: var(--fca-cm-muted); }
.fca-cm-alert.is-unread .fca-cm-thread-dot { visibility: visible; }

/* Link-style row (e.g. "Open full chat") */
.fca-cm-linkrow {
  display: block;
  padding: 12px 16px;
  text-align: center;
  color: var(--fca-cm-active);
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  border-top: 1px solid var(--fca-cm-border);
  cursor: pointer;
}

/* ── Hide FC's native mobile menu when ours is active (mobile only) ─────── */
@media (max-width: 768px) {
  body.fca-cm-active .fcom_mobile_menu { display: none !important; }

  /* Optional: hide FC's top-left hamburger. Our Menu button still opens the
     drawer by calling .click() on it, which works while display:none. */
  body.fca-cm-hide-hamburger .fcom_space_opener_btn { display: none !important; }

  /* Mirror FC's own mobile-menu behaviour so the bar never sits on top of
     something the user is trying to type into or tap. */

  /* Post drawer / comment modal open: FC drops its menu to z-index 0. */
  body.fcom_post_modal_opened .fca-cm-bar,
  body.fcom_post_modal_opened .fca-cm-tray,
  body.fcom_post_modal_opened .fca-cm-scrim { z-index: 0 !important; }

  /* On-screen keyboard open (FC toggles html.fcom_keyboard_open from
     visualViewport): hide the bar and release the reserved bottom padding so
     the composer / reply box gets the space. Keep the bar when it is our own
     tray the user is typing into. */
  html.fcom_keyboard_open .fca-cm:not(.is-tray-open) .fca-cm-bar { display: none !important; }
  html.fcom_keyboard_open body.fca-cm-active:not(.fca-cm-tray-open) {
    --fcom-mobile-menu-height: 0px !important;
  }

  /* FC's scroll-to-top FAB sits at z 1900 and would float over the open tray. */
  body.fca-cm-tray-open .fcom_scroll_to_top { display: none !important; }

  /* Scrolling down: FC slides its menu away; do the same. */
  .fca-cm-bar { transition: transform .3s ease; }
  body.fcom_scrolling-down_mbl .fca-cm:not(.is-tray-open) .fca-cm-bar { transform: translateY(100%); }

  /* Reserve space for our fixed bar. FC's layout already pads its content by
     var(--fcom-mobile-menu-height); that var reflects FC's (now hidden) native
     menu, so re-point it at OUR bar height (+ safe area). Defined on body so it
     wins over any :root-level value for all descendants. --fca-cm-bar-h is set
     inline on body by mobile-tray.js from the configured bar height. */
  body.fca-cm-active {
    --fcom-mobile-menu-height: calc(var(--fca-cm-bar-h, 64px) + env(safe-area-inset-bottom, 0px)) !important;
  }

}

/* ── Desktop: hide our mobile UI entirely ──────────────────────────────── */
@media (min-width: 769px) {
  .fca-cm { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  .fca-cm-tray,
  .fca-cm-scrim { transition: none; }
}
