/*
 * PD-1328: Communications > Inbox reply composer (desktop).
 * The message thread is the main content: the list always keeps at least 55%
 * of the conversation pane (a 56% track, so borders and rounding never dip under
 * 55%; never under 240px); the reply box takes at most what is left and scrolls
 * internally, with Send kept visible. The composer starts collapsed to a
 * single "Reply…" bar (communications-inbox-reply-collapse.js).
 * Scoped to #communications-reply-box / the inbox mailbox only: the CRM
 * customer workspace reuses .communications-reply-box but not this pane.
 * Loaded after admin-email-box.css so the editor override wins by order.
 * Phones (<=720px) keep the always-visible composer and is-composer-focused.
 */

.communications-reply-bar {
  display: none;
}

#communications-thread-reply-hint[hidden] {
  display: none;
}

.communications-reply-collapse {
  display: none;
}

@media (min-width: 721px) {
  .communications-mailbox-detail {
    grid-template-rows: auto auto minmax(max(240px, 56%), 1fr) auto auto minmax(0, auto);
  }

  .communications-mailbox-detail > .communications-conversation-head { grid-row: 1; }
  .communications-mailbox-detail > .communications-thread-settings { grid-row: 2; }
  .communications-mailbox-detail > .communications-message-list { grid-row: 3; }
  .communications-mailbox-detail > #communications-messages-load-more { grid-row: 4; }
  .communications-mailbox-detail > .communications-unmatched-thread-actions { grid-row: 5; }

  .communications-mailbox-detail > #communications-reply-box {
    grid-row: 6;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    gap: 8px;
    padding: 10px 14px;
  }

  /* The status line (an aria-live region: send accepted/failed, Twilio status)
     stays rendered when collapsed so it is seen and announced after a send. */
  #communications-reply-box.is-collapsed > :not(.communications-reply-bar, .communications-reply-actions),
  #communications-reply-box.is-collapsed > .communications-reply-actions > :not(#communications-thread-reply-status) {
    display: none;
  }

  #communications-reply-box.is-collapsed > .communications-reply-actions {
    position: static;
    padding: 0;
  }

  #communications-reply-box.is-collapsed {
    gap: 4px;
    padding-block: 6px;
  }

  #communications-reply-box.is-collapsed > .communications-reply-bar {
    display: flex;
  }

  .communications-reply-bar {
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 36px;
    padding: 6px 12px;
    border: 1px solid var(--line, #dbe3ee);
    border-radius: 8px;
    background: #f8fafc;
    color: #475569;
    font: inherit;
    font-size: 14px;
    text-align: left;
    cursor: text;
  }

  .communications-reply-bar:hover {
    border-color: #94a3b8;
    background: #ffffff;
  }

  .communications-reply-bar:focus-visible {
    outline: 3px solid #1d4ed8;
    outline-offset: 2px;
  }

  .communications-reply-bar-label {
    flex: 1 1 auto;
    min-width: 0;
  }

  .communications-reply-bar-channel,
  .communications-reply-bar-draft {
    flex: 0 0 auto;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
  }

  .communications-reply-bar-channel {
    background: #e0e7ff;
    color: #3730a3;
  }

  .communications-reply-bar-draft {
    background: #fef3c7;
    color: #78350f;
  }

  .communications-reply-bar-draft[hidden] {
    display: none;
  }

  .communications-reply-bar-key {
    flex: 0 0 auto;
    padding: 1px 6px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    background: #ffffff;
    color: #475569;
    font: 12px/1.4 ui-monospace, Menlo, monospace;
  }

  #communications-reply-box .email-composer-editor,
  #communications-reply-box .email-composer-preview {
    min-height: 96px;
    max-height: none;
  }

  /* Send stays visible while the capped composer scrolls. */
  #communications-reply-box .communications-reply-actions {
    position: sticky;
    bottom: 0;
    z-index: 1;
    margin-top: 0 !important;
    padding-bottom: 10px;
    background: #ffffff;
  }

  .communications-mailbox-detail > #communications-reply-box:not(.is-collapsed) {
    padding-bottom: 0;
  }

  #communications-reply-box .communications-reply-actions > .ops-summary-status {
    flex: 1 1 auto;
    min-width: 0;
  }

  .communications-reply-hint {
    flex: 0 1 auto;
    min-width: 0;
  }

  .communications-reply-hint .email-composer-hint {
    padding: 0;
    color: #64748b;
    font-size: 12px;
  }

  .communications-reply-collapse {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-width: 44px;
    min-height: 44px;
    font-size: 20px;
    line-height: 1;
  }
}

@media (min-width: 981px) {
  #communications-reply-box .communications-reply-grid {
    grid-template-columns: minmax(130px, 170px) minmax(200px, 1fr) minmax(170px, 240px);
  }
}

@media (max-width: 720px) {
  /* The signature note moved beside Send (PD-1328); on phones it wraps onto its own line above the actions. */
  #communications-reply-box .communications-reply-actions {
    flex-wrap: wrap;
  }

  .communications-reply-hint {
    order: -1;
    flex: 1 0 100%;
  }

  .communications-reply-hint .email-composer-hint {
    padding: 0;
    font-size: 12px;
  }
}
