/*
 * MOOS rich-text contract.
 *
 * This file is deliberately loaded after all page and product styles. Every
 * Tiptap instance and every saved rich-text renderer must obey the same
 * sizing, wrapping, media and table rules, regardless of its host module.
 */
.tiptap-editor,
.tiptap-editor *,
.rich-content,
.rich-content * {
  box-sizing: border-box;
}

.tiptap-editor,
.tiptap-controls,
.tiptap-toolbar,
.tiptap-table-tools,
.tiptap-surface,
.tiptap-content,
.rich-content {
  min-width: 0;
  max-width: 100%;
}

.tiptap-editor {
  width: 100%;
  overflow: hidden;
}

.tiptap-controls {
  position: sticky;
  top: 0;
  z-index: 3;
  width: 100%;
  background: #f7faf8;
}

.tiptap-toolbar,
.tiptap-table-tools {
  width: 100%;
  flex-wrap: wrap;
}

/* The legacy editor layer used overflow-x:auto here. Browsers then compute
 * overflow-y as auto as well, producing a tiny vertical scrollbar beside the
 * table buttons. Controls wrap instead, so this strip must never scroll. */
.tiptap-table-tools {
  overflow: visible;
}

.tiptap-table-tools[hidden] {
  display: none !important;
}

.tiptap-toolbar {
  position: static;
}

.tiptap-select-wrap {
  display: inline-grid;
  position: relative;
  min-width: 0;
  align-items: center;
}
.tiptap-select-wrap > select {
  grid-area: 1 / 1;
}

.tiptap-mobile-more-toggle,
.tiptap-mobile-more-menu {
  display: none !important;
}

.tiptap-surface {
  position: relative;
  width: 100%;
  overflow-x: hidden;
}

.tiptap-content,
.rich-content {
  width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Shared rich-text rhythm. Saved Tiptap blank lines are empty paragraphs, so
 * both the editor and every renderer must reserve space for them. */
:is(.tiptap-content, .rich-content) p {
  margin: 0 0 .8em;
}

:is(.tiptap-content, .rich-content) p:empty {
  min-height: 1.55em;
  margin: 0;
}

:is(.tiptap-content, .rich-content) p:last-child {
  margin-bottom: 0;
}

.tiptap-content > *,
.rich-content > *,
.tiptap-content p,
.tiptap-content li,
.tiptap-content blockquote,
.tiptap-content h1,
.tiptap-content h2,
.tiptap-content h3,
.tiptap-content th,
.tiptap-content td,
.rich-content p,
.rich-content li,
.rich-content blockquote,
.rich-content h1,
.rich-content h2,
.rich-content h3,
.rich-content th,
.rich-content td {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.tiptap-content pre,
.rich-content pre {
  max-width: 100%;
  overflow-x: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.tiptap-content table,
.rich-content table {
  display: table;
  width: 100%;
  max-width: 100%;
  table-layout: fixed;
}

.tiptap-content img,
.rich-content img {
  max-width: 100%;
  height: auto;
}

.tiptap-image-node {
  position: relative;
  display: inline-block;
  max-width: 100%;
}

/* Keep the selection chrome from visually covering an adjacent inline image. */
.tiptap-image-node + .tiptap-image-node {
  margin-inline-start: 8px;
}

.tiptap-image-node:not(.ProseMirror-selectednode):not(.is-image-range-selected):hover img {
  outline: 0;
  box-shadow: inset 0 0 0 2px rgba(23, 107, 80, .45);
}

.tiptap-image-overlay {
  position: absolute;
  z-index: 6;
  box-sizing: border-box;
  border: 2px solid #176b50;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .72);
  pointer-events: none;
}

.tiptap-image-overlay[hidden] {
  display: none !important;
}

.tiptap-image-overlay.is-resizing {
  transition: none !important;
}

.tiptap-image-resize-handle {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 16px;
  height: 16px;
  padding: 0;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #176b50;
  box-shadow: 0 2px 7px rgba(12, 48, 36, .28);
  cursor: nwse-resize;
  opacity: 1;
  pointer-events: auto;
  touch-action: none;
}

.tiptap-image-resize-handle:focus-visible {
  outline: 2px solid #176b50;
  outline-offset: 3px;
}

.tiptap-image-mobile-actions {
  display: none;
}

.tiptap-image-node.ProseMirror-selectednode img {
  outline: 0;
  box-shadow: none;
}

.tiptap-image-node.is-image-range-selected img,
.tiptap-editor.is-all-selected .tiptap-image-node img {
  outline: 2px solid #2e70ac;
  outline-offset: 1px;
  box-shadow: none;
}

.upload-row .upload-remove-button,
.rich-upload-row .upload-remove-button {
  display: inline-grid;
  width: 32px;
  min-width: 32px;
  height: 32px;
  padding: 0;
  place-items: center;
  border: 1px solid #d8c6c3;
  border-radius: 5px;
  color: #9b342e;
  background: #fff;
  cursor: pointer;
}

.upload-row .upload-remove-button:hover,
.rich-upload-row .upload-remove-button:hover {
  border-color: #bd716b;
  color: #842a25;
  background: #fff3f1;
}

.upload-row .upload-remove-button:focus-visible,
.rich-upload-row .upload-remove-button:focus-visible {
  outline: 2px solid #176b50;
  outline-offset: 2px;
}

.rich-upload-queue {
  display: grid;
  gap: 6px;
  margin: 8px 10px 0;
}

.rich-upload-row {
  display: grid;
  min-height: 42px;
  grid-template-columns: 20px minmax(0, 1fr) 32px;
  gap: 8px;
  align-items: center;
  padding: 4px 6px 4px 10px;
  border: 1px solid #d6e0db;
  border-radius: 6px;
  color: #2b443a;
  background: #f8fbf9;
}

.rich-upload-row > i {
  justify-self: center;
  color: #42695a;
  font-size: 16px;
}

.rich-upload-row > span {
  overflow: hidden;
  color: #2b443a;
  font-size: 13px;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rich-upload-feedback {
  min-height: 30px;
  padding: 6px 12px 8px;
}

.project-narrative.rich-content,
.communication-content.rich-content {
  width: 100%;
}

.communication-content.rich-content img {
  width: auto;
  max-width: min(100%, 560px);
  max-height: none;
}

@media (max-width: 760px) {
  .tiptap-editor {
    border-radius: 8px;
  }

  .rich-upload-queue {
    margin-inline: 8px;
  }

  .rich-upload-row {
    min-height: 52px;
    grid-template-columns: 20px minmax(0, 1fr) 44px;
    padding: 4px 4px 4px 10px;
  }

  .rich-upload-row .upload-remove-button {
    width: 44px;
    min-width: 44px;
    height: 44px;
  }

  .rich-upload-feedback {
    padding-inline: 10px;
  }

  .tiptap-toolbar,
  .tiptap-table-tools {
    gap: 2px;
    padding: 6px;
    overflow: visible;
  }

  .tiptap-toolbar {
    flex-wrap: nowrap;
    gap: 4px;
  }

  .tiptap-toolbar > :not(.tiptap-mobile-primary):not(.tiptap-mobile-more-toggle) {
    display: none !important;
  }

  .tiptap-toolbar > .tiptap-mobile-primary,
  .tiptap-mobile-more-toggle {
    display: inline-grid !important;
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    place-items: center;
  }

  .tiptap-mobile-more-toggle[aria-expanded="true"] {
    color: #0f6048;
    background: #e5f2ec;
  }

  .tiptap-mobile-more-menu {
    position: absolute;
    top: 56px;
    right: 6px;
    z-index: 7;
    width: min(320px, calc(100% - 12px));
    grid-template-columns: repeat(4, minmax(44px, 1fr));
    gap: 6px;
    padding: 10px;
    border: 1px solid #cbd8d2;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 16px 38px rgba(18, 49, 37, .18);
  }

  .tiptap-mobile-more-menu[hidden] {
    display: none !important;
  }

  .tiptap-mobile-more-menu:not([hidden]) {
    display: grid !important;
  }

  .tiptap-mobile-more-menu :is(button, .toolbar-color) {
    display: inline-grid;
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    place-items: center;
  }

  .tiptap-mobile-more-menu select {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    grid-column: span 2;
  }

  .tiptap-toolbar select {
    min-width: 0;
    max-width: 112px;
  }

  .tiptap-content {
    min-height: 170px;
    padding: 14px;
  }

  .communication-dialog .modal-actions {
    padding-bottom: calc(10px + var(--safe-bottom));
  }

  :is(.tiptap-content, .rich-content) img {
    max-height: min(48dvh, 360px);
    object-fit: contain;
    object-position: left center;
  }

  .tiptap-image-overlay .tiptap-image-mobile-actions {
    display: grid;
    position: absolute;
    left: 0;
    bottom: 6px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    width: min(292px, calc(100% - 16px));
    padding: 5px;
    border: 1px solid rgba(200, 214, 208, .95);
    border-radius: 7px;
    background: rgba(255, 255, 255, .96);
    box-shadow: 0 4px 16px rgba(12, 48, 36, .2);
    line-height: 1.2;
    pointer-events: auto;
    transform: none;
  }

  .tiptap-image-mobile-actions button {
    min-width: 0;
    min-height: 44px;
    padding: 5px;
    border: 1px solid #c8d6d0;
    border-radius: 5px;
    color: #31493f;
    background: #fff;
    font: inherit;
    font-size: 11px;
    cursor: pointer;
  }

  .tiptap-image-mobile-actions button[aria-pressed="true"] {
    border-color: #176b50;
    color: #0f6048;
    background: #e5f2ec;
  }

  .tiptap-image-mobile-actions .danger-text {
    color: #a23832 !important;
  }
}

@media (max-width: 760px) and (pointer: coarse) {
  .tiptap-image-node + .tiptap-image-node {
    margin-inline-start: 0;
  }

  .tiptap-image-resize-handle {
    display: none !important;
  }
}

/* Modal scroll ownership: header/footer stay fixed and only the middle pane
 * scrolls. The editor itself never creates a competing vertical scrollbar. */
.communication-modal-form {
  min-height: 0;
  overflow: hidden;
}

.communication-form-scroll {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: #91a39b transparent;
}

.communication-form-scroll::-webkit-scrollbar {
  width: 8px;
}

.communication-form-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.communication-form-scroll::-webkit-scrollbar-thumb {
  min-height: 44px;
  border: 2px solid transparent;
  border-radius: 999px;
  background: #91a39b;
  background-clip: padding-box;
}

.communication-form-scroll::-webkit-scrollbar-button,
.communication-form-scroll::-webkit-scrollbar-corner {
  display: none;
  width: 0;
  height: 0;
}

.communication-modal-form .tiptap-editor,
.communication-modal-form .tiptap-surface,
.communication-modal-form .tiptap-content {
  overflow-y: visible;
}

.communication-mobile-review {
  display: none;
}

.communication-upload-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.communication-upload-actions input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
}

.upload-processing {
  color: #176b50;
  font-weight: 700;
}

.communication-modal-form[data-upload-processing="true"] [type="submit"] {
  cursor: wait;
  opacity: .62;
}

.communication-modal-form .upload-row {
  grid-template-columns: 20px minmax(0, 1fr) minmax(92px, auto) 30px;
}

@media (max-width: 760px) {
  .communication-modal-form .attachment-dropzone {
    display: grid;
    height: max-content;
    min-height: max-content;
    grid-template-columns: 20px minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-items: flex-start;
  }

  .communication-modal-form .attachment-dropzone > i {
    grid-column: 1;
    grid-row: 1;
  }

  .communication-modal-form .attachment-dropzone > span {
    min-width: 0;
    grid-column: 2;
    grid-row: 1;
  }

  .communication-upload-actions {
    display: grid;
    width: 100%;
    grid-column: 1 / -1;
    grid-row: 2;
    grid-template-columns: 1fr 1fr;
  }

  .communication-upload-actions .secondary-button {
    min-height: 44px;
    justify-content: center;
  }

  .communication-modal-form .upload-row {
    grid-template-columns: 20px minmax(0, 1fr) 30px;
  }

  .communication-modal-form .upload-row small {
    grid-column: 2;
  }

  .communication-mobile-review {
    display: grid;
    gap: 10px;
    margin-top: 16px;
    padding: 12px;
    border: 1px solid #cbd8d2;
    border-radius: 7px;
    background: #f7faf8;
  }

  .communication-review-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .communication-review-heading :is(.eyebrow, h3) {
    margin: 0;
  }

  .communication-review-errors {
    padding: 4px 7px;
    border-radius: 999px;
    color: #8c2f2a;
    background: #fae9e7;
    font-size: 11px;
    font-weight: 750;
  }

  .communication-review-items {
    display: grid;
    gap: 6px;
  }

  .communication-review-items button {
    display: flex;
    width: 100%;
    min-height: 44px;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 10px;
    border: 1px solid #d9e3de;
    border-radius: 5px;
    color: #385049;
    background: #fff;
    font: inherit;
    font-size: 12px;
    text-align: left;
  }

  .communication-review-items button::after {
    color: #75857e;
    content: "›";
    font-size: 18px;
  }

  .communication-review-items button strong {
    margin-left: auto;
    color: #172c25;
    text-align: right;
  }
}

/* Communication selectors use explicit native-independent states. Web
 * Awesome resets otherwise make checked inputs function but look unchecked. */
.communication-modal-form .product-selector > div,
.communication-modal-form .product-selector [id$="_products"] {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 7px;
}

.communication-modal-form .product-selector [id$="_products"] > div {
  display: contents;
}

.communication-modal-form .product-selector [id$="_products"] > div[hidden] {
  display: none;
}

.communication-modal-form .product-selector label,
.communication-modal-form .visibility-selector label {
  cursor: pointer;
  transition: border-color .14s ease, background .14s ease, box-shadow .14s ease;
}

.communication-modal-form .product-selector label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid #d4dfda;
  border-radius: 7px;
  background: #fff;
}

.communication-modal-form .product-selector label:has(input:checked),
.communication-modal-form .visibility-selector label:has(input:checked) {
  border-color: #176b50;
  background: #edf7f2;
  box-shadow: 0 0 0 2px rgba(23, 107, 80, .1);
}

.communication-modal-form .product-selector input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  display: inline-grid;
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  margin: 0;
  place-content: center;
  border: 1.5px solid #9aada5;
  border-radius: 5px;
  background: #fff;
}

.communication-modal-form .product-selector input[type="checkbox"]::before,
.communication-modal-form .product-selector input[type="checkbox"]::after {
  content: none;
  display: none;
}

.communication-modal-form .product-selector input[type="checkbox"]:checked {
  border-color: #176b50;
  background: #176b50;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='white' stroke-linecap='round' stroke-linejoin='round' stroke-width='2.25' d='M3 8.5 6.4 12 13 4.5'/%3E%3C/svg%3E");
  background-position: center;
  background-repeat: no-repeat;
  background-size: 12px 12px;
}

.communication-modal-form .visibility-selector {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  justify-content: flex-start;
  gap: 10px;
}

.communication-modal-form .visibility-selector legend {
  width: 100%;
  margin-bottom: 7px;
}

.communication-modal-form .visibility-selector label {
  display: flex;
  flex: 0 1 260px;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 8px 11px;
  border: 1px solid #d4dfda;
  border-radius: 7px;
  background: #fff;
}

.communication-modal-form .visibility-selector input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  display: grid;
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  margin: 0;
  place-content: center;
  border: 1.5px solid #91a69d;
  border-radius: 50%;
  background: #fff;
}

.communication-modal-form .visibility-selector input[type="radio"]::after {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #176b50;
  opacity: 0;
  transform: scale(.5);
  transition: opacity .12s ease, transform .12s ease;
}

.communication-modal-form .visibility-selector input[type="radio"]:checked {
  border-color: #176b50;
}

.communication-modal-form .visibility-selector input[type="radio"]:checked::after {
  opacity: 1;
  transform: scale(1);
}

.communication-modal-form .product-selector input:focus-visible,
.communication-modal-form .visibility-selector input:focus-visible {
  outline: 2px solid #176b50;
  outline-offset: 3px;
}
.rich-upload-picker {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 0;
}

.rich-upload-picker input[type="file"] {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.rich-upload-picker label {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  border: 1px solid #bdcec6;
  border-radius: 7px;
  color: #315d4d;
  background: #fff;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
}

.rich-upload-picker label:hover { border-color: #8fb3a4; background: #f3f8f5; }
.rich-upload-picker input:focus-visible + label { outline: 2px solid #2b8267; outline-offset: 2px; }
.rich-upload-picker small { color: #718078; font-size: 10px; }
