.message-modal {
  width: min(600px, calc(100% - 1.25rem));
  color: #172421;
  background: #f7faf9;
  border: 1px solid rgba(15, 118, 110, .18);
  border-radius: 20px;
  overflow: hidden;
}

.message-modal .modal-close {
  color: #172421;
  background: #fff;
  border-color: rgba(23, 36, 33, .16);
  box-shadow: 0 4px 16px rgba(17, 52, 48, .1);
}

.message-panel { padding: clamp(1.35rem, 5vw, 2.5rem); }
.message-panel h2 { max-width: 12ch; margin-bottom: 1.25rem; color: #172421; font-size: clamp(2rem, 6vw, 2.8rem); }
.message-panel .eyebrow { color: #0f766e; }
.message-panel label { color: #263733; font-size: .9rem; }
.message-panel label span { color: #687873; }

body:not(.admin-body) .message-panel input,
body:not(.admin-body) .message-panel textarea {
  color: #172421;
  background: #fff;
  border: 1px solid #c9d7d3;
  box-shadow: inset 0 1px 2px rgba(17, 52, 48, .03);
}

body:not(.admin-body) .message-panel input::placeholder,
body:not(.admin-body) .message-panel textarea::placeholder { color: #71807c; opacity: 1; }

body:not(.admin-body) .message-panel input:focus,
body:not(.admin-body) .message-panel textarea:focus {
  border-color: #0f766e;
  box-shadow: 0 0 0 3px rgba(15, 118, 110, .13);
}

.message-panel .form-error { color: #a13a27; }
.message-panel .linked-listing { color: #21433d; background: #dff1ec; border: 1px solid #c1e1d9; }
.message-panel .full-button { min-height: 50px; color: #fff; background: #0f766e; }
.message-panel .full-button:hover { background: #0b655f; }

#message-thread-view:not([hidden]) {
  min-height: min(680px, 82vh);
  display: flex;
  flex-direction: column;
}

#message-thread-view .back-link {
  width: fit-content;
  margin: 0 0 .45rem;
  padding: .25rem 0;
  color: #0f766e;
  text-decoration: none;
}

#message-thread-view .back-link:hover { text-decoration: underline; }
#message-thread-view h2 { max-width: none; margin-bottom: .35rem; font-size: clamp(1.7rem, 5vw, 2.25rem); }

.message-thread {
  min-height: 260px;
  max-height: none;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: .7rem;
  margin: .8rem 0;
  padding: 1rem;
  color: #172421;
  background: #e9f0ed;
  border: 1px solid #d6e2de;
  border-radius: 16px;
  overscroll-behavior: contain;
}

.message-thread .bubble {
  width: fit-content;
  max-width: min(84%, 440px);
  margin: 0;
  padding: .75rem .9rem .55rem;
  color: #172421;
  background: #fff;
  border: 1px solid rgba(23, 36, 33, .08);
  border-radius: 16px 16px 16px 5px;
  box-shadow: 0 4px 14px rgba(17, 52, 48, .07);
}

.message-thread .bubble.mine {
  align-self: flex-end;
  margin-left: 0;
  color: #fff;
  background: #0f766e;
  border-color: #0f766e;
  border-radius: 16px 16px 5px 16px;
}

.message-thread .bubble p { line-height: 1.42; overflow-wrap: anywhere; }
.message-thread .bubble small { margin-top: .35rem; color: #74827e; font-size: .7rem; }
.message-thread .bubble.mine small { color: rgba(255, 255, 255, .72); }

.message-panel .reply-form {
  padding: .65rem;
  align-items: flex-end;
  background: #fff;
  border: 1px solid #d6e2de;
  border-radius: 15px;
}

body:not(.admin-body) .message-panel .reply-form textarea {
  min-height: 48px;
  max-height: 130px;
  padding: .65rem .7rem;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.message-panel .reply-form button {
  min-width: 72px;
  min-height: 44px;
  padding: .55rem .9rem;
  background: #0f766e;
  border-radius: 11px;
}

.message-panel .notification-button,
.message-panel .saved-messages-link {
  width: 100%;
  margin-top: .55rem;
  padding: .75rem 1rem;
  color: #0f766e;
  background: transparent;
  border: 1px solid #b8d7d0;
  border-radius: 11px;
  text-align: center;
  text-decoration: none;
}

.message-panel .notification-button:hover,
.message-panel .saved-messages-link:hover { background: #e5f2ef; }

@media (max-width: 640px) {
  .message-modal {
    width: 100%;
    max-height: 100dvh;
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .message-panel { padding: 1.15rem; }
  #message-thread-view:not([hidden]) { min-height: 100%; }
  .message-thread .bubble { max-width: 88%; }
  .message-panel .reply-form { position: sticky; bottom: 0; }
}
