:root {
  --xmd-border: var(--bs-border-color, #d9dee3);
  --xmd-muted-bg: var(--bs-tertiary-bg, #f6f7f8);
  --xmd-body-bg: var(--bs-body-bg, #fff);
  --xmd-body-color: var(--bs-body-color, #212529);
  --xmd-primary: var(--bs-primary, #0d6efd);
  --xmd-code-bg: #f4f5f7;
}

.xmd-editor {
  position: relative;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  color: var(--xmd-body-color);
  box-sizing: border-box;
}

.xmd-editor *,
.xmd-editor *::before,
.xmd-editor *::after {
  box-sizing: border-box;
}

.xmd-editor .CodeMirror,
.xmd-editor .CodeMirror-scroll,
.xmd-editor .editor-toolbar,
.xmd-editor .editor-preview,
.xmd-editor .editor-preview-side,
.xmd-editor .xmd-editor-status {
  max-width: 100%;
  min-width: 0;
}

.xmd-editor .editor-toolbar {
  display: flex;
  min-height: 46px;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  padding: 5px;
  border-color: var(--xmd-border);
  border-radius: 6px 6px 0 0;
  background: var(--xmd-muted-bg);
  opacity: 1;
}

.xmd-editor .editor-toolbar::before,
.xmd-editor .editor-toolbar::after {
  display: none;
}

.xmd-editor .editor-toolbar button {
  width: 34px;
  min-width: 34px;
  height: 34px;
  margin: 0;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--xmd-body-color) !important;
  background: transparent;
  line-height: 32px;
}

.xmd-editor .editor-toolbar button:hover,
.xmd-editor .editor-toolbar button.active {
  border-color: var(--xmd-border);
  background: var(--xmd-body-bg);
}

.xmd-editor .editor-toolbar button:focus-visible {
  outline: 2px solid var(--xmd-primary);
  outline-offset: 1px;
}

.xmd-editor .editor-toolbar i.separator {
  width: 1px;
  height: 24px;
  margin: 0 4px;
  border: 0;
  background: var(--xmd-border);
}

.xmd-editor .CodeMirror {
  border-color: var(--xmd-border);
  border-radius: 0 0 6px 6px;
  color: var(--xmd-body-color);
  background: var(--xmd-body-bg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  line-height: 1.65;
}

.xmd-editor .CodeMirror-cursor {
  border-left-color: var(--xmd-body-color);
}

.xmd-editor .CodeMirror-selected,
.xmd-editor .CodeMirror-focused .CodeMirror-selected {
  background: rgba(13, 110, 253, 0.18);
}

.xmd-editor .editor-preview,
.xmd-editor .editor-preview-side {
  color: var(--xmd-body-color);
  background: var(--xmd-body-bg);
}

.xmd-editor .editor-preview-side {
  border-color: var(--xmd-border);
}

.xmd-editor-status {
  min-height: 26px;
  padding: 4px 8px;
  border: 1px solid var(--xmd-border);
  border-top: 0;
  border-radius: 0 0 6px 6px;
  background: var(--xmd-muted-bg);
  font-size: 12px;
  text-align: right;
}

.xmd-editor.has-more-tools .xmd-editor-status {
  border-radius: 0;
}

.xmd-editor-more {
  display: flex;
  min-height: 42px;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 5px 7px;
  border: 1px solid var(--xmd-border);
  border-top: 0;
  border-radius: 0 0 6px 6px;
  background: var(--xmd-body-bg);
}

.xmd-editor-more[hidden],
.xmd-editor-more-panel[hidden] {
  display: none;
}

.xmd-editor-more-toggle,
.xmd-editor-more-tool {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  justify-content: center;
  gap: 0.38rem;
  padding: 0.3rem 0.55rem;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--xmd-body-color);
  background: transparent;
  font: inherit;
  font-size: 0.84rem;
  line-height: 1.2;
  cursor: pointer;
}

.xmd-editor-more-toggle:hover,
.xmd-editor-more-toggle[aria-expanded="true"],
.xmd-editor-more-tool:hover {
  border-color: var(--xmd-border);
  background: var(--xmd-muted-bg);
}

.xmd-editor-more-toggle:focus-visible,
.xmd-editor-more-tool:focus-visible {
  outline: 2px solid var(--xmd-primary);
  outline-offset: 1px;
}

.xmd-editor-more-toggle .icon-angle-down {
  color: var(--bs-secondary-color, #626b73);
  transition: transform 0.16s ease;
}

.xmd-editor-more.is-open .xmd-editor-more-toggle .icon-angle-down {
  transform: rotate(180deg);
}

.xmd-editor-more-panel {
  display: flex;
  min-width: 0;
  align-items: center;
  flex: 1 1 auto;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding-left: 0.5rem;
  border-left: 1px solid var(--xmd-border);
}

.xmd-editor .CodeMirror + .editor-preview + .editor-preview-side + .xmd-editor-status,
.xmd-editor .CodeMirror + .editor-preview + .xmd-editor-status {
  border-radius: 0 0 6px 6px;
}

.xmd-editor-quick .editor-toolbar {
  min-height: 42px;
  padding: 3px;
}

.xmd-editor-quick .editor-toolbar button {
  width: 32px;
  min-width: 32px;
  height: 32px;
  line-height: 30px;
}

.xmd-editor-quick .CodeMirror {
  min-height: 140px;
}

.xmd-editor-quick .CodeMirror-scroll {
  min-height: 140px;
}

.xmd-legacy-switch {
  min-height: 38px;
  padding: 6px 8px;
  border: 1px solid var(--xmd-border);
  border-radius: 6px;
  background: var(--xmd-muted-bg);
}

.xmd-prose {
  min-width: 0;
  color: inherit;
  line-height: 1.75;
  overflow-wrap: anywhere;
}

.xmd-prose > :first-child {
  margin-top: 0;
}

.xmd-prose > :last-child {
  margin-bottom: 0;
}

.xmd-prose h1,
.xmd-prose h2,
.xmd-prose h3,
.xmd-prose h4,
.xmd-prose h5,
.xmd-prose h6 {
  margin: 1.25em 0 0.55em;
  letter-spacing: 0;
  line-height: 1.35;
}

.xmd-prose h1 { font-size: 1.7rem; }
.xmd-prose h2 { font-size: 1.45rem; }
.xmd-prose h3 { font-size: 1.25rem; }
.xmd-prose h4 { font-size: 1.1rem; }
.xmd-prose h5,
.xmd-prose h6 { font-size: 1rem; }

.xmd-prose p,
.xmd-prose ul,
.xmd-prose ol,
.xmd-prose pre,
.xmd-prose blockquote,
.xmd-prose table {
  margin: 0 0 1rem;
}

.xmd-prose ul,
.xmd-prose ol {
  padding-left: 1.7rem;
}

.xmd-prose .task-list,
.xmd-prose .contains-task-list { padding-left: 0; list-style: none; }
.xmd-prose .task-list-item { list-style: none; }
.xmd-prose .task-list-item > input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  margin: 0 0.48rem 0 0;
  vertical-align: -0.12rem;
  accent-color: var(--xmd-primary);
  opacity: 1;
}

.xmd-prose .xmd-math-inline { display: inline; }
.xmd-prose .xmd-math-block,
.xmd-prose .katex-display {
  max-width: 100%;
  margin: 1rem 0;
  padding: 0.15rem 0;
  overflow-x: auto;
  overflow-y: hidden;
  text-align: center;
  -webkit-overflow-scrolling: touch;
}
.xmd-prose .katex { font-size: 1.05em; }

.xmd-prose blockquote {
  padding: 0.6rem 0.85rem;
  border-left: 4px solid var(--xmd-primary);
  color: var(--bs-secondary-color, #5b6269);
  background: var(--xmd-muted-bg);
}

.xmd-prose blockquote > :last-child {
  margin-bottom: 0;
}

.xmd-prose code {
  padding: 0.12rem 0.32rem;
  border-radius: 4px;
  color: #b42352;
  background: var(--xmd-code-bg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.9em;
}

.xmd-prose pre {
  max-width: 100%;
  padding: 0.85rem 1rem;
  border: 1px solid var(--xmd-border);
  border-radius: 6px;
  background: var(--xmd-code-bg);
  overflow: auto;
}

.xmd-prose pre code {
  padding: 0;
  color: inherit;
  background: transparent;
}

.xmd-prose table {
  display: block;
  width: 100%;
  border-collapse: collapse;
  overflow-x: auto;
}

.xmd-prose th,
.xmd-prose td {
  min-width: 7rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--xmd-border);
  text-align: left;
  vertical-align: top;
}

.xmd-prose th {
  background: var(--xmd-muted-bg);
  font-weight: 600;
}

.xmd-prose img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  cursor: zoom-in;
}

.xmd-prose hr {
  margin: 1.5rem 0;
  border-color: var(--xmd-border);
  opacity: 1;
}

.xmd-prose a {
  overflow-wrap: anywhere;
}

.xmd-modal .modal-content,
.xmd-lightbox .modal-content {
  border-radius: 6px;
}

.xmd-lightbox [data-xmd-lightbox-image] {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 9rem);
  margin: 0 auto;
  object-fit: contain;
}

.xmd-insert-attachment {
  white-space: nowrap;
}

@media (max-width: 767.98px) {
  #quick_reply_form,
  #quick_reply_form .message,
  #quick_reply_form .EasyMDEContainer,
  #form .EasyMDEContainer {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .xmd-editor .editor-toolbar {
    align-content: center;
    flex-wrap: wrap;
    overflow-x: hidden;
  }

  .xmd-editor .editor-toolbar .no-mobile,
  .xmd-editor .editor-toolbar i.separator {
    display: none;
  }

  .xmd-editor .editor-toolbar button {
    width: 32px;
    min-width: 32px;
    flex: 0 0 32px;
  }

  .xmd-editor-quick .CodeMirror,
  .xmd-editor-quick .CodeMirror-scroll {
    min-height: 132px;
  }

  .xmd-editor-more {
    align-items: stretch;
    flex-direction: column;
  }

  .xmd-editor-more-toggle {
    align-self: flex-start;
  }

  .xmd-editor-more-panel {
    width: 100%;
    padding: 0.45rem 0 0;
    border-top: 1px solid var(--xmd-border);
    border-left: 0;
  }

  .xmd-legacy-switch {
    align-items: flex-start !important;
    flex-direction: column;
  }

  .xmd-prose h1 { font-size: 1.45rem; }
  .xmd-prose h2 { font-size: 1.3rem; }
  .xmd-prose h3 { font-size: 1.16rem; }
}

[data-bs-theme="dark"] {
  --xmd-code-bg: #1f2328;
}

[data-bs-theme="dark"] .xmd-prose code {
  color: #ff8fb3;
}
