/* Phase 3A.3.2.4 — Social Inbox responsive / mobile final polish (opt-in) */
/* Source of truth: approved 3A.1 / 3A.2 / 3A.3.1 visuals — geometry only. */

#inboxView.social-inbox-mobile-final {
  --simf-touch: 44px;
}

/* ——— ≤1024: one-pane list/detail (no squeezed two-pane, no blank column) ——— */
@media (max-width: 1024px) {
  #inboxView.social-inbox-mobile-final .social-inbox-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  #inboxView.social-inbox-mobile-final .social-inbox-list-panel,
  #inboxView.social-inbox-mobile-final .social-inbox-column {
    width: 100%;
    max-width: none;
    min-width: 0;
    flex: 1 1 auto;
  }

  #inboxView.social-inbox-mobile-final .social-inbox-detail-panel {
    min-width: 0;
    max-width: none;
    width: 100%;
  }

  #inboxView.social-inbox-mobile-final .social-inbox-context-panel {
    display: none;
  }

  /* LIST state: detail column must not reserve layout width */
  #inboxView.social-inbox-mobile-final:not(.social-detail-open) .social-inbox-detail-panel {
    display: none;
  }

  /* DETAIL state: list hidden; detail fills inbox */
  #inboxView.social-inbox-mobile-final.social-detail-open .social-inbox-list-panel {
    display: none;
  }

  #inboxView.social-inbox-mobile-final.social-detail-open .social-inbox-detail-panel,
  #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: none;
    min-width: 0;
    flex: 1 1 auto;
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  #inboxView.social-inbox-mobile-final.social-detail-open .social-inbox-back-btn,
  #inboxView.social-inbox-mobile-final.social-detail-open [data-social-back] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--simf-touch);
    min-width: var(--simf-touch);
  }

  #inboxView.social-inbox-mobile-final.social-detail-open .social-chat-header,
  #inboxView.social-inbox-mobile-final.social-detail-open .social-chat-header__aside,
  #inboxView.social-inbox-mobile-final.social-detail-open .social-chat-composer,
  #inboxView.social-inbox-mobile-final.social-detail-open .chat-bubble,
  #inboxView.social-inbox-mobile-final.social-detail-open .chat-bubble__media {
    max-width: 100%;
    min-width: 0;
  }

  #inboxView.social-inbox-mobile-final.social-detail-open .chat-bubble-row.is-outbound .chat-bubble {
    max-width: min(100%, 85%);
  }

  /*
   * Tablet/mobile detail: otomasyon toolbar tek satır, kompakt.
   */
  #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-inbox-toolbar.social-inbox-toolbar--slim {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    flex-wrap: nowrap;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow: visible;
    gap: 6px;
    padding: 4px 8px;
    flex-shrink: 0;
  }

  #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-inbox-toolbar__row,
  #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-inbox-toolbar__primary,
  #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-inbox-toolbar__actions {
    display: flex;
    flex-wrap: nowrap;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    flex: 1 1 auto;
    gap: 6px;
    overflow: visible;
  }

  #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-inbox-toolbar__row > .primary-button,
  #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-inbox-toolbar__row > .ghost-button,
  #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-inbox-toolbar__primary .primary-button,
  #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-inbox-toolbar__primary .ghost-button,
  #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-inbox-toolbar__actions .primary-button,
  #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-inbox-toolbar__actions .ghost-button {
    flex: 1 1 0;
    min-width: 0;
    min-height: 2rem;
    max-width: none;
    padding: 0.28rem 0.4rem;
    font-size: 0.72rem;
    line-height: 1.15;
    white-space: nowrap;
  }

  /* Badge overflow: visible under one-pane detail; tablet intrinsic width fixed below (768–1024). */
  #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-header-badges {
    flex-wrap: wrap;
    overflow: visible;
    max-width: 100%;
  }

  #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-header-badges__item .badge {
    overflow: visible;
    text-overflow: clip;
    white-space: nowrap;
    max-width: none;
  }
}

/* Tablet: bottom nav + header badge readability (768–1024) */
@media (min-width: 768px) and (max-width: 1024px) {
  body.is-tablet-layout #inboxView.social-inbox-mobile-final.active {
    height: calc(100dvh - 3rem - var(--mobile-bottom-nav-h, 4rem) - var(--mobile-safe-bottom, 0px));
    max-height: calc(100dvh - 3rem - var(--mobile-bottom-nav-h, 4rem) - var(--mobile-safe-bottom, 0px));
    overflow: hidden;
  }

  body.is-tablet-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-chat-thread {
    display: block;
    flex: 1 1 0%;
    min-height: 0;
    height: 0;
    max-height: none;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    overscroll-behavior-y: contain;
    padding-bottom: calc(var(--mobile-bottom-nav-h, 4rem) + var(--mobile-safe-bottom, 0px) + var(--mobile-social-composer-h, 7rem) + 1rem);
  }

  body.is-tablet-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-chat-composer {
    margin-bottom: calc(var(--mobile-bottom-nav-h, 4rem) + var(--mobile-safe-bottom, 0px));
  }

  /*
   * Header aside was max-width:52% + badges flex-shrink → platform badge box ~45px
   * while "WhatsApp" needs ~74–82px (scrollW===clientW on badge can still lie when
   * the flex item is already sized below true intrinsic width).
   */
  #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-chat-header {
    gap: 8px;
  }

  #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-chat-header__identity {
    flex: 1 1 auto;
    min-width: 0;
  }

  #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-chat-header__aside {
    flex: 0 0 auto;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    min-width: 0;
    max-width: min(68%, 400px);
  }

  #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-header-badges {
    display: flex;
    flex: 0 0 auto;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    min-width: max-content;
    max-width: 100%;
    overflow: visible;
  }

  #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-header-badges__item:not([hidden]),
  #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-header-badges__more:not([hidden]) {
    flex: 0 0 auto;
    flex-shrink: 0;
    min-width: max-content;
  }

  #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-header-badges__item .badge,
  #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-header-badges__more {
    flex: 0 0 auto;
    flex-shrink: 0;
    min-width: max-content;
    width: max-content;
    max-width: none;
    overflow: visible;
    text-overflow: clip;
    white-space: nowrap;
    box-sizing: border-box;
    padding-left: 12px;
    padding-right: 12px;
  }

  #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-chat-header__offer,
  #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-crm-menu,
  #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-crm-menu__trigger {
    flex-shrink: 0;
  }
}

/* Mid desktop (>1024, CRM still auto-hidden ≤1320): avoid clipped chat chrome */
@media (min-width: 1025px) and (max-width: 1319.98px) {
  #inboxView.social-inbox-mobile-final .social-inbox-detail-panel {
    min-width: 0;
  }

  #inboxView.social-inbox-mobile-final .social-chat-header__aside {
    max-width: 100%;
    min-width: 0;
  }

  #inboxView.social-inbox-mobile-final .chat-bubble,
  #inboxView.social-inbox-mobile-final .chat-bubble__media {
    max-width: 100%;
  }
}

/* ——— Mobile (body.is-mobile-layout) ——— */
body.is-mobile-layout #inboxView.social-inbox-mobile-final.is-mobile-social .social-inbox-list,
body.is-mobile-layout #inboxView.social-inbox-mobile-final #socialInboxList {
  padding-bottom: 0.75rem;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior-y: contain;
}

/* Cards: natural height; never flex-grow/stretch to fill list viewport */
body.is-mobile-layout #inboxView.social-inbox-mobile-final .social-inbox-list .social-inbox-card,
body.is-mobile-layout #inboxView.social-inbox-mobile-final .social-inbox-list .social-crm-card,
body.is-mobile-layout #inboxView.social-inbox-mobile-final #socialInboxList .social-crm-card.social-inbox-card {
  flex: 0 0 auto;
  flex-grow: 0;
  flex-shrink: 0;
  align-self: stretch;
  height: auto;
  min-height: 0;
  justify-content: start;
  align-content: start;
}

/* Height only — do NOT zero flex-grow on .social-identity__text (flex:1 / basis 0% → width 0). */
body.is-mobile-layout #inboxView.social-inbox-mobile-final #socialInboxList .social-crm-card.social-inbox-card .inbox-card-main,
body.is-mobile-layout #inboxView.social-inbox-mobile-final #socialInboxList .social-crm-card.social-inbox-card .social-crm-card__identity {
  height: auto;
  min-height: 0;
  justify-content: flex-start;
  align-self: auto;
}

body.is-mobile-layout #inboxView.social-inbox-mobile-final #socialInboxList .social-crm-card.social-inbox-card .social-identity__text {
  flex: 1 1 auto;
  flex-grow: 1;
  min-width: 0;
  width: auto;
  height: auto;
  overflow: hidden;
}

body.is-mobile-layout #inboxView.social-inbox-mobile-final .social-filter-chip,
body.is-mobile-layout #inboxView.social-inbox-mobile-final .social-inbox-refresh-btn,
body.is-mobile-layout #inboxView.social-inbox-mobile-final [data-social-back],
body.is-mobile-layout #inboxView.social-inbox-mobile-final .social-crm-menu__trigger,
body.is-mobile-layout #inboxView.social-inbox-mobile-final [data-social-menu-toggle],
body.is-mobile-layout #inboxView.social-inbox-mobile-final [data-chat-msg-toggle],
body.is-mobile-layout #inboxView.social-inbox-mobile-final [data-social-open-offer] {
  min-height: var(--simf-touch);
  min-width: var(--simf-touch);
}

/* Header: keep actions reachable with long identity (additive; do not redesign grid) */
body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-chat-header,
body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-chat-header__identity,
body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-chat-header__aside {
  min-width: 0;
  max-width: 100%;
}

body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-chat-header__identity strong,
body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-chat-header__identity h2,
body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-chat-header__identity .social-username {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-header-badges,
body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-header-badges__item {
  max-width: 100%;
  min-width: 0;
}

/* Mobile: otomasyon butonları tek satır */
body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-inbox-toolbar__row,
body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-inbox-toolbar__primary,
body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-inbox-toolbar__actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  width: 100%;
  max-width: 100%;
  overflow: visible;
}

body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-inbox-toolbar__row > .primary-button,
body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-inbox-toolbar__row > .ghost-button,
body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-inbox-toolbar__primary .primary-button,
body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-inbox-toolbar__primary .ghost-button,
body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open #socialInboxDetail .social-inbox-toolbar__actions .ghost-button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 2rem;
  padding: 0.28rem 0.35rem;
  font-size: 0.7rem;
}

/* Composer controls — only attach/send need 44px; template chips must stay compact */
body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-reply-composer__attach-icon,
body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-reply-composer__send,
body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-chat-composer .social-reply-composer__attach-icon,
body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-chat-composer .social-reply-composer__send {
  min-height: var(--simf-touch);
  min-width: var(--simf-touch);
}

body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-reply-composer__field textarea {
  min-height: 40px;
  max-height: 9rem;
  height: auto;
  overflow-y: hidden;
  field-sizing: content;
}

/* Mobile WhatsApp composer: keep bar + chips + send fully visible */
body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-chat-composer {
  padding: 6px 10px calc(8px + var(--mobile-safe-bottom, 0px));
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-reply-composer {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  gap: 6px;
}

body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-reply-hint {
  margin: 0;
  font-size: 0.72rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-reply-hint--warn {
  padding: 5px 8px;
}

body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .wa-template-pick,
body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .wa-template-pick--compact {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  margin: 0;
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .wa-template-pick__label {
  flex: 0 0 auto;
  margin: 0;
  font-size: 0.68rem;
  font-weight: 600;
  color: #64748b;
}

body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .wa-template-pick__chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  min-width: 0;
  flex: 1 1 auto;
  width: auto;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 1px;
}

body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .wa-template-pick__chips::-webkit-scrollbar {
  display: none;
}

body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .wa-template-chip {
  flex: 0 0 auto;
  min-width: 0;
  min-height: 28px;
  max-width: none;
  padding: 3px 9px;
  font-size: 0.7rem;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
}

body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .wa-template-chip__hint,
body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .wa-template-pick--compact .wa-template-chip__hint {
  display: none;
}

body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-reply-composer__bar {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 4px 6px;
}

body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-reply-composer__field--inline {
  flex: 1 1 auto;
  min-width: 0;
}

body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-reply-composer__field textarea {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  font-size: 16px; /* iOS zoom önleme */
}

body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-reply-composer__send {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
}

body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-reply-composer__media-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: 0;
  margin: 0;
  padding: 0;
}

/* Menus stay inside viewport */
body.is-mobile-layout #inboxView.social-inbox-mobile-final .social-crm-menu__panel,
body.is-mobile-layout #inboxView.social-inbox-mobile-final .chat-msg-menu__panel {
  max-width: min(100vw - 16px, 320px);
  max-height: min(70vh, 420px);
  overflow: auto;
}

body.is-mobile-layout #inboxView.social-inbox-mobile-final .social-crm-menu__panel button,
body.is-mobile-layout #inboxView.social-inbox-mobile-final .chat-msg-menu__panel button {
  min-height: var(--simf-touch);
}

/*
 * Empty / loading / no-result — ONLY direct empty markers.
 * Do NOT target nested .muted-text (phone lines use muted-text → caused tall cards).
 */
body.is-mobile-layout #inboxView.social-inbox-mobile-final .social-inbox-empty,
body.is-mobile-layout #inboxView.social-inbox-mobile-final #socialInboxList > .social-inbox-empty,
body.is-mobile-layout #inboxView.social-inbox-mobile-final #socialInboxList > .muted-text {
  padding: 1.25rem 1rem 5.5rem;
  text-align: center;
}

/*
 * Prevent page-level horizontal bleed from inbox chrome.
 * IMPORTANT: overflow-x:hidden alone computes overflow-y to auto and steals
 * touch scroll from .social-chat-thread on iOS. Keep both axes non-scroll here.
 */
body.is-mobile-layout #inboxView.social-inbox-mobile-final,
body.is-mobile-layout #inboxView.social-inbox-mobile-final .social-inbox-layout,
body.is-mobile-layout #inboxView.social-inbox-mobile-final .social-inbox-detail-panel,
body.is-mobile-layout #inboxView.social-inbox-mobile-final #socialInboxDetail,
body.is-mobile-layout #inboxView.social-inbox-mobile-final .social-inbox-detail--v3,
body.is-mobile-layout #inboxView.social-inbox-mobile-final .social-chat-stage,
body.is-mobile-layout #inboxView.social-inbox-mobile-final .social-chat-thread-panel {
  max-width: 100%;
  overflow-x: hidden;
  overflow-y: hidden;
}

/* Only the message thread scrolls on mobile detail — must be height-bounded */
body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-chat-thread-panel {
  flex: 1 1 0%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-chat-thread[data-social-chat-thread],
body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-chat-thread {
  display: block;
  flex: 1 1 0%;
  min-height: 0;
  height: 0; /* flex scrollport: take remaining space, do not grow with content */
  max-height: none;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior-y: contain;
  padding-bottom: calc(var(--mobile-social-composer-h, 7rem) + 1.25rem);
}

/* Back control must stay tappable above identity / badges */
body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-inbox-back-btn,
body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open [data-social-back] {
  position: relative;
  z-index: 6;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--simf-touch);
  min-height: var(--simf-touch);
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

body.is-mobile-layout #inboxView.social-inbox-mobile-final.social-detail-open .social-chat-header.social-inbox-detail__hero {
  position: sticky;
  top: 0;
  z-index: 5;
  flex-shrink: 0;
  background: var(--sid-surface, #fff);
}