/* ==========================================================================
   Circle Chat — mobile messenger viewport (global, must load before paint)
   Active when body.feed-page.is-circle-chat-active
   ========================================================================== */

@media (max-width: 767px) {
  html.is-circle-chat-active,
  html.is-circle-chat-active body {
    overflow: hidden !important;
    height: 100dvh;
    max-height: 100dvh;
    overscroll-behavior: none;
    touch-action: manipulation;
  }

  html.is-circle-chat-active #root,
  html.is-circle-chat-active .app-shell {
    min-height: 0;
    flex: 1 1 auto;
    overflow: hidden !important;
    max-height: 100dvh;
  }

  html.is-circle-chat-active .app-main,
  html.is-circle-chat-active .app-shell__content,
  html.is-circle-chat-active.has-mobile-bottom-nav .app-main,
  html.is-circle-chat-active.has-mobile-bottom-nav .app-shell__content {
    overflow: hidden !important;
    min-height: 0;
    flex: 1 1 auto;
    max-height: 100dvh;
    padding-bottom: 0 !important;
  }

  html.is-circle-chat-active .mobile-bottom-nav,
  html.is-circle-chat-active .mobile-bottom-nav[hidden] {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
    height: 0 !important;
    min-height: 0 !important;
    padding: 0 !important;
  }

  html.is-circle-chat-active .hd-ticker {
    flex-shrink: 0;
  }

  /* Pin feed page to viewport below navbar + ticker */
  body.feed-page.is-circle-chat-active .sf-page--feed {
    position: fixed;
    top: var(--fa-chat-viewport-top, 96px);
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 25;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 0 !important;
    margin: 0;
    background: var(--fa-bg, #0A1628);
  }

  body.feed-page.is-circle-chat-active .sf-feed-layout {
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 0 !important;
    gap: 0;
  }

  body.feed-page.is-circle-chat-active .sf-feed-side {
    display: none !important;
  }

  body.feed-page.is-circle-chat-active .sf-feed-main {
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  body.feed-page.is-circle-chat-active .sf-feed-head {
    display: none !important;
  }

  /* circle-chat-top: Fandom tabs + circle toolbar */
  body.feed-page.is-circle-chat-active .sf-feed-sticky-chrome,
  body.feed-page.is-circle-chat-active .circle-chat-top {
    flex: 0 0 auto;
    flex-shrink: 0;
    padding: 0 10px 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  }

  body.feed-page.is-circle-chat-active .sf-feed-tabs--primary {
    display: none;
  }

  body.feed-page.is-circle-chat-active #feed-composer {
    display: none !important;
  }

  body.feed-page.is-circle-chat-active #feed-status {
    display: none !important;
  }

  body.feed-page.is-circle-chat-active #feed-list,
  body.feed-page.is-circle-chat-active .sf-feed-list {
    flex: 1 1 auto;
    min-height: 0 !important;
    height: 0;
    overflow: hidden !important;
    display: flex;
    flex-direction: column;
    padding: 0 10px !important;
    margin: 0 !important;
  }

  body.feed-page.is-circle-chat-active #feed-stream-mount,
  body.feed-page.is-circle-chat-active .sf-circle-chat-root {
    flex: 1 1 auto;
    min-height: 0 !important;
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  body.feed-page.is-circle-chat-active .circle-chat-shell,
  body.feed-page.is-circle-chat-active .sf-circle-chat {
    flex: 1 1 auto;
    min-height: 0 !important;
    max-height: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    gap: 0;
  }

  /* Only scrollable region */
  body.feed-page.is-circle-chat-active .circle-chat-messages,
  body.feed-page.is-circle-chat-active .sf-circle-chat-scroll {
    flex: 1 1 auto;
    min-height: 0 !important;
    max-height: none !important;
    overflow-y: auto !important;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 12px 2px;
    padding-bottom: calc(var(--fa-chat-composer-height, 72px) + env(safe-area-inset-bottom, 0px) + 12px);
    border: none;
    background: transparent;
  }

  /* Fixed composer — never in document scroll flow */
  body.feed-page.is-circle-chat-active .circle-chat-composer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 120;
    flex: 0 0 auto;
    background: var(--fa-bg, #0A1628);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-form {
    position: relative;
    margin: 0;
    padding: 10px 14px;
    border: none;
    background: transparent;
    box-shadow: none;
  }

  body.feed-page.is-circle-chat-active .sf-feed-ptr {
    display: none !important;
  }

  body.feed-page.is-circle-chat-active .sf-feed-main {
    touch-action: none;
  }

  body.feed-page.is-circle-chat-active .circle-chat-messages,
  body.feed-page.is-circle-chat-active .sf-circle-chat-scroll {
    touch-action: pan-y;
  }

  body.feed-page.is-circle-chat-active .sf-feed-ptr {
    display: none !important;
  }

  /* ---- Compact circle header (~110–130px total) ---- */

  body.feed-page.is-circle-chat-active .sf-feed-circle-tabs {
    display: none !important;
  }

  body.feed-page.is-circle-chat-active .sf-feed-tabs-wrap {
    margin: 0;
    padding: 0;
  }

  body.feed-page.is-circle-chat-active .circle-chat-top {
    padding: 0 10px 0;
  }

  body.feed-page.is-circle-chat-active .sf-circle-toolbar.sf-circle-toolbar--conversation,
  body.feed-page.is-circle-chat-active .sf-circle-toolbar.circle-chat-header {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0;
    padding: 6px 0 4px;
    border: none;
    border-radius: 0;
    background: transparent;
  }

  body.feed-page.is-circle-chat-active .sf-circle-toolbar-nav {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 6px;
    min-width: 0;
  }

  body.feed-page.is-circle-chat-active .sf-circle-back-btn {
    appearance: none;
    -webkit-appearance: none;
    display: inline-flex;
    align-items: center;
    gap: 1px;
    margin: 0;
    padding: 4px 6px 4px 0;
    border: none;
    border-radius: 0;
    background: transparent !important;
    color: var(--teal, #00c2cb);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    box-shadow: none;
  }

  body.feed-page.is-circle-chat-active .sf-circle-back-btn:active {
    opacity: 0.75;
    background: transparent !important;
  }

  body.feed-page.is-circle-chat-active .sf-circle-toolbar-back {
    display: none !important;
  }

  body.feed-page.is-circle-chat-active .sf-circle-toolbar-name,
  body.feed-page.is-circle-chat-active .circle-chat-header-title {
    font-size: 16px;
    font-weight: 800;
    line-height: 1.15;
    margin: 0;
  }

  body.feed-page.is-circle-chat-active .sf-circle-toolbar-lead,
  body.feed-page.is-circle-chat-active .circle-chat-header-meta {
    margin: 0;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    gap: 4px;
  }

  body.feed-page.is-circle-chat-active .sf-circle-toolbar-manage {
    align-self: center;
    min-height: 28px;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: none;
  }

  body.feed-page.is-circle-chat-active .sf-circle-view-tabs,
  body.feed-page.is-circle-chat-active .circle-chat-tabs {
    display: flex;
    width: 100%;
    margin: 2px 0 0;
    padding: 2px;
    gap: 2px;
    border-radius: 8px;
  }

  body.feed-page.is-circle-chat-active .sf-circle-view-tab {
    flex: 1 1 0;
    min-width: 0;
    padding: 6px 8px;
    font-size: 11px;
    font-weight: 600;
    text-align: center;
  }

  /* ---- Message bubbles (DM-style) ---- */

  body.feed-page.is-circle-chat-active .sf-circle-chat-messages {
    gap: 0;
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-msg {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    max-width: 76%;
    width: fit-content;
    align-self: flex-start;
    margin-bottom: 8px;
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-msg.is-self {
    margin-left: auto;
    align-self: flex-end;
    flex-direction: row;
    max-width: 76%;
    width: fit-content;
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-msg.is-grouped {
    margin-top: -2px;
    margin-bottom: 2px;
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-msg.is-grouped.is-group-end {
    margin-bottom: 8px;
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-avatar {
    width: 28px;
    flex-shrink: 0;
    margin-bottom: 0;
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-msg.is-grouped .sf-circle-chat-avatar {
    visibility: hidden;
  }

  body.feed-page.is-circle-chat-active .sf-avatar--chat {
    width: 28px;
    height: 28px;
    font-size: 11px;
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-bubble {
    width: fit-content;
    max-width: 100%;
    min-width: min(2.75rem, 100%);
    padding: 10px 13px;
    border-radius: 18px 18px 18px 6px;
    background: rgba(30, 42, 58, 0.95);
    border: none;
    box-shadow: none;
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-msg.is-grouped .sf-circle-chat-bubble {
    border-top-left-radius: 6px;
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-msg.is-self .sf-circle-chat-bubble {
    border-radius: 18px 18px 6px 18px;
    background: rgba(0, 70, 78, 0.72);
    border: 1px solid rgba(0, 194, 203, 0.12);
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-msg.is-self.is-grouped .sf-circle-chat-bubble {
    border-top-right-radius: 6px;
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-meta {
    display: flex;
    align-items: baseline;
    gap: 4px;
    margin: 0 0 3px;
    font-size: 11px;
    line-height: 1.2;
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-name {
    font-size: 11px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.72);
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-text {
    margin: 0;
    font-size: 15px;
    line-height: 1.42;
    color: rgba(255, 255, 255, 0.94);
    overflow-wrap: break-word;
    word-break: normal;
    white-space: pre-wrap;
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-time-foot {
    margin: 4px 0 0;
    padding: 0;
    font-size: 10px;
    line-height: 1;
    color: rgba(255, 255, 255, 0.32);
    text-align: right;
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-msg:not(.is-self) .sf-circle-chat-time-foot {
    text-align: left;
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-time {
    font-size: inherit;
    color: inherit;
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-share-card {
    margin-top: 4px;
    padding: 8px 10px;
    border-radius: 8px;
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-share-card .sf-quote-post-body,
  body.feed-page.is-circle-chat-active .sf-circle-chat-share-card .sf-quote-sub {
    font-size: 12px;
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-share {
    margin-top: 6px;
    padding: 6px 8px;
    border-radius: 8px;
    font-size: 12px;
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-empty {
    margin: 24px 8px;
    font-size: 14px;
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-load-more {
    margin: 0 auto 8px;
    font-size: 11px;
    padding: 4px 10px;
    min-height: 32px;
  }

  /* ---- Messages scroll area ---- */

  body.feed-page.is-circle-chat-active .circle-chat-messages,
  body.feed-page.is-circle-chat-active .sf-circle-chat-scroll {
    padding: 6px 10px;
    padding-bottom: calc(var(--fa-chat-composer-height, 68px) + env(safe-area-inset-bottom, 0px) + 8px);
  }

  /* ---- Composer (integrated, not heavy) ---- */

  body.feed-page.is-circle-chat-active .circle-chat-composer {
    background: rgba(10, 22, 40, 0.98);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.18);
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-form {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    min-height: 56px;
    max-height: none;
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-input-wrap {
    margin: 0;
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-input {
    min-height: 40px;
    max-height: 96px;
    padding: 10px 16px;
    font-size: 16px;
    line-height: 1.35;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.06);
    box-shadow: none;
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-input:focus {
    border-color: rgba(0, 194, 203, 0.35);
    background: rgba(255, 255, 255, 0.08);
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-send {
    width: 42px;
    height: 42px;
    min-width: 42px;
    min-height: 42px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--teal, #00c2cb);
    color: var(--navy, #0a1628);
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-send:disabled {
    opacity: 0.35;
    background: rgba(0, 194, 203, 0.45);
    color: rgba(10, 22, 40, 0.6);
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-send-icon {
    width: 18px;
    height: 18px;
    margin-left: 1px;
  }

  body.feed-page.is-circle-chat-active .sf-circle-chat-error {
    padding: 0 12px 6px;
    font-size: 11px;
  }

  /* Circle inbox — WhatsApp / Instagram style list */
  body.feed-page .sf-circle-inbox {
    padding: 0 4px;
  }

  body.feed-page .sf-circle-inbox-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 8px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  }

  body.feed-page .sf-circle-inbox-title {
    margin: 0;
    font-family: var(--font-display, 'Barlow Condensed', sans-serif);
    font-size: 18px;
    font-weight: 800;
    letter-spacing: 0.03em;
    color: var(--white, #fff);
  }

  body.feed-page .sf-circle-inbox-create {
    flex-shrink: 0;
    min-height: 32px;
    padding: 4px 10px;
    font-size: 12px;
  }

  body.feed-page .sf-circle-inbox-list {
    list-style: none;
    margin: 0;
    padding: 0;
  }

  body.feed-page .sf-circle-inbox-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 8px;
    border: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    background: transparent;
    color: inherit;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
  }

  body.feed-page .sf-circle-inbox-row:active {
    background: rgba(0, 194, 203, 0.08);
  }

  body.feed-page .sf-circle-inbox-avatar {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display, 'Barlow Condensed', sans-serif);
    font-size: 18px;
    font-weight: 800;
    color: var(--white, #fff);
    background: rgba(0, 194, 203, 0.18);
    border: 1px solid rgba(0, 194, 203, 0.25);
  }

  body.feed-page .sf-circle-inbox-body {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
  }

  body.feed-page .sf-circle-inbox-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
  }

  body.feed-page .sf-circle-inbox-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--white, #fff);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body.feed-page .sf-circle-inbox-time {
    flex-shrink: 0;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.42);
  }

  body.feed-page .sf-circle-inbox-preview {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.55);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body.feed-page .sf-circle-inbox-preview--empty {
    font-style: italic;
    color: rgba(255, 255, 255, 0.32);
  }

  body.feed-page .sf-circle-inbox-meta {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.48);
  }

  body.feed-page .sf-circle-inbox-chevron {
    display: none;
  }

  /* Circle inbox — hide duplicate Fandom title, show list full width */
  body.feed-page.feed-circle-inbox .sf-feed-head {
    display: none;
  }

  body.feed-page.feed-circle-inbox #feed-composer {
    display: none !important;
  }

  body.feed-page.feed-circle-inbox .sf-feed-tabs--primary {
    margin-bottom: 0;
  }

  body.feed-page.feed-circle-open .sf-feed-head {
    display: none;
  }

  body.feed-page.feed-circle-open #feed-circle-toolbar {
    padding-left: var(--fa-mobile-edge, 12px);
    padding-right: var(--fa-mobile-edge, 12px);
  }

  body.feed-page.feed-circle-open .sf-circle-toolbar--conversation {
    border: none;
    background: transparent;
    margin: 0;
    padding: 8px 0 6px;
  }

  body.feed-page.feed-circle-open .sf-circle-back-btn {
    appearance: none;
    -webkit-appearance: none;
    background: transparent !important;
    border: none;
    box-shadow: none;
    color: var(--teal, #00c2cb);
  }

  body.feed-page .sf-empty-state--circles {
    text-align: center;
    padding: 32px 16px;
  }

  body.feed-page .sf-empty-state--circles .sf-empty-title {
    margin: 0 0 8px;
    font-size: 18px;
    font-weight: 700;
    color: var(--white, #fff);
  }

  body.feed-page .sf-empty-state--circles .sf-empty-lead {
    margin: 0 0 20px;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.55);
    line-height: 1.45;
  }

  /* Circles product — /circles/:id chat viewport */
  body.circles-page.is-circle-chat-active .sf-page--circle-detail {
    position: fixed;
    top: var(--fa-chat-viewport-top, 96px);
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 25;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 0 !important;
    margin: 0;
    max-width: none;
    background: var(--fa-bg, #0A1628);
  }

  body.circles-page.is-circle-chat-active .sf-circle-detail-chrome {
    flex: 0 0 auto;
    padding: 0 10px 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  }

  body.circles-page.is-circle-chat-active .sf-circle-stream-mount {
    flex: 1 1 auto;
    min-height: 0 !important;
    height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 0 10px !important;
  }

  body.circles-page.is-circle-chat-active .sf-circle-chat-root,
  body.circles-page.is-circle-chat-active .circle-chat-shell,
  body.circles-page.is-circle-chat-active .sf-circle-chat {
    flex: 1 1 auto;
    min-height: 0 !important;
    height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  body.circles-page.is-circle-chat-active:not(.circles-shell-page) .circle-chat-messages,
  body.circles-page.is-circle-chat-active:not(.circles-shell-page) .sf-circle-chat-scroll {
    flex: 1 1 auto;
    min-height: 0 !important;
    overflow-y: auto !important;
    padding-bottom: calc(var(--fa-chat-composer-height, 72px) + env(safe-area-inset-bottom, 0px) + 12px);
  }

  /* CirclesShell: composer stays in flex flow — scroll is not covered */
  body.circles-shell-page.circles-page.is-circle-chat-active .sf-page--circle-detail {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    flex: 1 1 0%;
    min-height: 0;
    overflow: hidden;
  }

  body.circles-shell-page.circles-page.is-circle-chat-active .sf-circle-detail-chrome {
    flex: 0 0 auto;
    padding: 0;
  }

  body.circles-shell-page.circles-page.is-circle-chat-active .sf-circle-stream-mount {
    padding: 0 !important;
    height: auto;
    flex: 1 1 0%;
    min-height: 0;
    overflow: hidden;
  }

  body.circles-shell-page.circles-page.is-circle-chat-active .sf-circle-chat-scroll {
    flex: 1 1 0% !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.5rem !important;
  }

  body.circles-shell-page.circles-page.is-circle-chat-active .circle-chat-composer {
    position: relative !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    z-index: auto;
    flex: 0 0 auto !important;
  }

  /* Non-shell circles chat keeps fixed composer fallback */
  body.circles-page.is-circle-chat-active:not(.circles-shell-page) .circle-chat-composer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 120;
    background: var(--fa-bg, #0A1628);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  body.circles-page.is-circle-chat-active:not(.circles-shell-page) .sf-circle-chat-scroll {
    padding-bottom: calc(var(--fa-chat-composer-height, 72px) + env(safe-area-inset-bottom, 0px) + 12px);
  }

  body.circles-page.is-circle-chat-active #circle-composer {
    display: none !important;
  }

  body.circles-page.circles-inbox-page .mobile-bottom-nav {
    display: flex !important;
  }
}
