/*
 * 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-toolbar {
  position: static;
}

.tiptap-surface {
  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 {
  max-width: 100%;
}

.project-narrative.rich-content,
.communication-content.rich-content {
  width: 100%;
}

@media (max-width: 760px) {
  .tiptap-editor {
    border-radius: 8px;
  }

  .tiptap-toolbar,
  .tiptap-table-tools {
    gap: 2px;
    padding: 6px;
    overflow: visible;
  }

  .tiptap-toolbar select {
    min-width: 0;
    max-width: 112px;
  }

  .tiptap-content {
    min-height: 170px;
    padding: 14px;
  }
}

/* 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 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 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;
}
