/* =============================================================
   AskPerTask — Message Provider Composer  (apt-message-composer.css)

   Loaded on every front-end request — the real "Message Provider" modal
   can be opened from many different surfaces (services archive, vendor
   archive, homepage grid, single listing/vendor page, favorites,
   bookings list, account pages) with no single route to gate on. Every
   selector below is scoped to classes only this batch renders
   (.apt-msg-header, .apt-message-actions-secondary,
   .apt-msg-conversation-header, .hp-form--message-send), so this file is
   inert everywhere those classes are absent.

   MESSAGE-PROVIDER-COMPOSER-VISUAL-REDESIGN-1A
   ============================================================= */

:root {
  --apt-msg-text:       #1A1A1A;
  --apt-msg-muted:      #6B7280;
  --apt-msg-border:     #E5E7EB;
  --apt-msg-bg-card:    #F9FAFB;
  --apt-msg-blue:       #2D6CDF;
  --apt-msg-blue-light: #EAF1FD;
  --apt-msg-radius:     8px;
  --apt-msg-radius-sm:  4px;
}

/* ── Modal shell ────────────────────────────────────────────── */
.hp-modal:has(.apt-msg-header) {
  width: min(560px, calc(100vw - 48px));
  max-width: 560px;
  box-sizing: border-box;
  padding: 24px 24px 20px;
  max-height: 88vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
}

.hp-modal:has(.apt-msg-header) .hp-modal__title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--apt-msg-text);
  padding-bottom: 12px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--apt-msg-border);
}

/* ── Recipient header ───────────────────────────────────────── */
.hp-modal .apt-msg-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--apt-msg-bg-card);
  border: 1px solid var(--apt-msg-border);
  border-radius: var(--apt-msg-radius);
  margin-bottom: 18px;
}

.apt-msg-header__avatar {
  flex: 0 0 auto;
  display: block;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
}

.apt-msg-header__avatar img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.apt-msg-header__body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.apt-msg-header__eyebrow {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--apt-msg-muted);
}

.apt-msg-header__name {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.apt-msg-header__name a {
  color: var(--apt-msg-text);
  text-decoration: none;
}

.apt-msg-header__name a:hover {
  color: var(--apt-msg-blue);
}

.apt-msg-header__badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 3px;
}

/* ── Conversation-page identity strip (/account/messages/{id}/) ──────
   Same visual language as the modal header, just without the card
   background so it reads as part of the page rather than a floating
   card. */
.apt-msg-conversation-header {
  margin-bottom: 18px;
}

.apt-msg-conversation-header .apt-msg-header {
  background: transparent;
  border: none;
  padding: 0 0 14px;
  border-bottom: 1px solid var(--apt-msg-border);
  border-radius: 0;
  margin-bottom: 16px;
}

/* ── Message form (.hp-form--message-send) ───────────────────
   Field/button classes confirmed against the real rendered HivePress
   form markup (hp-form__field, hp-form__field--textarea, hp-field__label,
   hp-form__footer, hp-form__button) — same pattern already verified
   against apt-offer-modal.css's .hp-form--offer-make. */

.hp-modal .hp-form--message-send {
  margin-top: 0;
}

.hp-modal .hp-form--message-send .hp-form__field {
  margin-bottom: 18px;
}

.hp-modal .hp-form--message-send .hp-form__field:last-of-type {
  margin-bottom: 0;
}

.hp-modal .hp-form--message-send .hp-field__label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--apt-msg-text);
  margin-bottom: 4px;
}

.hp-modal .hp-form--message-send .hp-field__description {
  margin-bottom: 8px;
  font-size: 0.8rem;
  color: var(--apt-msg-muted);
  line-height: 1.4;
}

/* Message textarea — comfortable height, clean focus state. */
.hp-modal .hp-form--message-send .hp-form__field--textarea textarea {
  width: 100%;
  min-height: 130px;
  padding: 12px 14px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--apt-msg-text);
  background: #fff;
  border: 1.5px solid var(--apt-msg-border);
  border-radius: var(--apt-msg-radius-sm);
  outline: none;
  resize: vertical;
  box-sizing: border-box;
  line-height: 1.5;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.hp-modal .hp-form--message-send .hp-form__field--textarea textarea:focus {
  border-color: var(--apt-msg-blue);
  box-shadow: 0 0 0 3px var(--apt-msg-blue-light);
}

/* Validation errors — same red-border treatment used across the rest of
   the AskPerTask forms instead of a default/browser-looking outline. */
.hp-modal .hp-form--message-send input.hp-field--invalid,
.hp-modal .hp-form--message-send textarea.hp-field--invalid {
  border-color: #DC2626 !important;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1) !important;
}

.hp-modal .hp-form--message-send .hp-form__messages[data-component="messages"]:not(:empty) {
  padding: 12px 14px;
  border-radius: var(--apt-msg-radius-sm);
  font-size: 0.85rem;
  margin-bottom: 16px;
  border: 1px solid #FECACA;
  background: #FEF2F2;
  color: #DC2626;
}

/* Attachment field — genuinely supported (hp_message_allow_attachment is
   ON with jpg/png/webp/pdf); only clean spacing/border added, no new
   controls invented. */
.hp-modal .hp-form--message-send .hp-form__field--attachment_upload {
  padding: 10px 12px;
  background: var(--apt-msg-bg-card);
  border: 1px dashed var(--apt-msg-border);
  border-radius: var(--apt-msg-radius-sm);
}

/* Footer / Send button */
.hp-modal .hp-form--message-send .hp-form__footer {
  margin-top: 4px;
  padding-top: 4px;
}

.hp-modal .hp-form--message-send .hp-form__button {
  display: flex !important;
  align-items: center;
  justify-content: center;
  width: 100% !important;
  height: 50px;
  background: var(--apt-msg-blue) !important;
  color: #fff !important;
  font-size: 1rem;
  font-weight: 600;
  border: none !important;
  border-radius: var(--apt-msg-radius) !important;
  box-shadow: none !important;
  cursor: pointer;
  transition: background 0.15s ease;
}

.hp-modal .hp-form--message-send .hp-form__button:hover {
  background: #2559B8 !important;
}

.hp-modal .hp-form--message-send .hp-form__button:disabled,
.hp-modal .hp-form--message-send .hp-form__button[data-state="loading"] {
  background: #9CA3AF !important;
  cursor: not-allowed;
}

/* Secondary Cancel action — closes the modal via Fancybox's own
   [data-fancybox-close] trigger; see build_secondary_actions_html(). */
.hp-modal .apt-message-actions-secondary {
  margin-top: 10px;
}

.apt-message-cancel {
  display: block;
  width: 100%;
  padding: 10px;
  background: transparent;
  border: none;
  color: var(--apt-msg-muted);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
}

.apt-message-cancel:hover {
  color: var(--apt-msg-text);
}

/* ── Mobile (390px) ────────────────────────────────────────────
   Full usable width, avatar/name stay visible, textarea/buttons stay
   easy to tap, no horizontal overflow. */
@media (max-width: 480px) {
  .hp-modal:has(.apt-msg-header) {
    width: calc(100vw - 24px);
    max-width: calc(100vw - 24px);
    padding: 18px 16px 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }

  .hp-modal .apt-msg-header {
    gap: 10px;
    padding: 10px;
  }

  .apt-msg-header__avatar,
  .apt-msg-header__avatar img {
    width: 38px;
    height: 38px;
  }

  .apt-msg-header__name {
    font-size: 0.95rem;
  }

  .hp-modal .hp-form--message-send .hp-form__field--textarea textarea {
    min-height: 110px;
  }
}
