:root {
  --wysi-primary: #70d48b;
  --wysi-hover: #59aa6f;
  --wysi-highlight: #dff5e5;
}

#wysiwyg-editor *,
.wysi-editor * {
  font: revert !important;
  list-style: revert !important;
  padding: revert !important;
}

#wysi-svg-icons {
  display: none;
}

.wysi-wrapper {
  display: flex;
  flex-direction: column;
  position: relative;
  border-radius: 5px;
  font-size: 16px;
  line-height: 1.5;
  outline: 1px solid rgba(160, 160, 160, 0.3);
}

.wysi-wrapper {
  display: inline-flex;
  width: 100%;
  font-weight: normal !important;
  font-style: normal !important;
}

.wysi-wrapper:focus-within {
  outline-color: var(--wysi-primary);
}

.wysi-wrapper + textarea {
  display: none;
}

.wysi-toolbar {
  display: flex;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 5px;
  border-radius: 5px 5px 0 0;
  background-color: #eee;
  box-sizing: border-box;
}

.wysi-autohide .wysi-toolbar {
  display: none;
}

.wysi-autohide:focus-within .wysi-toolbar {
  display: flex;
  flex-wrap: nowrap;
  position: absolute;
  min-width: 100%;
  left: 50%;
  transform: translate(-50%, -100%);
  margin-top: -5px;
  border-radius: 5px;
  outline: 1px solid rgba(160, 160, 160, 0.3);
}

.wysi-toolbar *,
.wysi-toolbar *:before,
.wysi-toolbar *:after {
  box-sizing: inherit;
}

.wysi-toolbar button {
  display: inline-flex;
  align-items: center;
  width: auto;
  height: 30px;
  margin: 0 5px 0 0;
  padding: 0;
  border: 0;
  border-radius: 3px;
  color: #444;
  background-color: transparent;
  font-family: inherit;
  font-size: 1em;
  font-weight: 400;
  text-transform: none;
  box-shadow: none;
  cursor: pointer;
}

.wysi-listbox > button,
.wysi-popover > button,
.wysi-toolbar > button {
  justify-content: center;
  width: 32px;
  border: 1px solid #ddd;
  background-color: #fff;
  transition: all 0.2s;
}

.wysi-listbox > button {
  width: auto;
  min-width: 40px;
  padding: 0 8px;
  justify-content: space-between;
}

.wysi-toolbar button:hover,
.wysi-toolbar button:focus,
.wysi-listbox button[aria-expanded="true"] {
  background-color: #fff;
}

.wysi-toolbar button[aria-pressed="true"] {
  color: var(--wysi-primary);
  background-color: var(--wysi-highlight);
}

.wysi-toolbar button[aria-pressed="true"]:hover {
  background-color: var(--wysi-highlight);
  mix-blend-mode: multiply;
}

.wysi-toolbar button * {
  pointer-events: none;
}

.wysi-toolbar button i {
  font-size: 14px;
}

.wysi-toolbar svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.wysi-listbox {
  position: relative;
}

.wysi-listbox > button {
  justify-content: space-between;
  width: 40px;
  padding: 0 4px 0 2px;
}

.wysi-listbox > button:after {
  content: "";
  display: block;
  width: 6px;
  height: 6px;
  transform: rotateZ(45deg);
  border: solid currentColor;
  border-width: 0 1.5px 1.5px 0;
  box-sizing: border-box;
}

.wysi-listbox div {
  position: absolute;
  margin-top: -1px;
  z-index: 1;
  border-radius: 0 0 3px 3px;
  background-color: #fff;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
  overflow: hidden;
}

.wysi-listbox > button[aria-expanded="false"] + div {
  display: none;
}

.wysi-listbox div button {
  display: flex;
  width: 100%;
  height: 30px;
  padding: 0 10px;
  border-radius: 3px;
  text-align: left;
  cursor: pointer;
}

.wysi-listbox div button:focus {
  background-color: #eee;
}

/** Format tool **/
.wysi-format button {
  font-size: 0.875em;
}

.wysi-format > button {
  width: 120px;
  padding: 0 10px;
}

.wysi-format div {
  min-width: 160px;
  padding: 5px;
}

.wysi-format button[data-option^="h"] {
  font-weight: bold;
}

.wysi-format button[data-option="h1"] {
  font-size: 1.25em;
}

.wysi-format button[data-option="h2"] {
  font-size: 1.125em;
}

.wysi-format button[data-option="h3"] {
  font-size: 1em;
}

/** End of Format tool **/

.wysi-popover {
  position: relative;
  margin-right: 5px;
}

.wysi-popover > button {
  margin: 0;
}

.wysi-popover > button[aria-expanded="false"] + div {
  display: none;
}

.wysi-popover > div {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  position: absolute;
  width: 320px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1;
  padding: 20px;
  border-radius: 8px;
  background-color: #fff;
  font-size: 0.95em;
  line-height: 1.3;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
}

.wysi-popover > div:before {
  content: "";
  display: block;
  position: absolute;
  width: 10px;
  height: 6px;
  left: 50%;
  top: -6px;
  transform: translateX(-50%);
  border-style: solid;
  border-width: 0 5px 6px 5px;
  border-color: transparent;
  border-bottom-color: #fff;
}

.wysi-popover label {
  width: 100%;
  margin-bottom: 8px;
  font-size: 1em;
}

.wysi-popover span {
  display: block;
  width: 100%;
  margin-bottom: 5px;
  line-height: 1.5;
}

.wysi-popover input[type] {
  width: 100%;
  height: 38px;
  margin: 5px 0 15px 0;
  padding: 0 12px;
  border: 1px solid #ccc !important;
  border-radius: 5px;
  color: #444;
  background-color: #fff;
  font-family: inherit;
  font-size: 14px;
  box-sizing: border-box;
  outline: none !important;
  box-shadow: none !important;
}

.wysi-popover .wysi-popover-actions {
  display: flex !important;
  width: 100% !important;
  justify-content: flex-end !important;
  margin-top: 10px !important;
  padding: 0 !important;
  position: static !important;
  box-shadow: none !important;
  background: transparent !important;
  flex-wrap: nowrap !important;
}

.wysi-popover > div button {
  height: 36px;
  margin: 0;
  padding: 0 20px;
  border: 1px solid #ccc;
  border-radius: 5px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.wysi-popover .wysi-popover-actions button {
  margin-left: 8px;
}

.wysi-popover .wysi-popover-actions button:last-child {
  border: 0;
  color: #fff;
  background-color: var(--wysi-primary);
}

.wysi-popover .wysi-popover-actions button:last-child:hover {
  background-color: var(--wysi-hover);
}

.wysi-popover .wysi-remove-link {
  width: 100%;
  margin-top: 5px;
  color: #f56565;
  border-color: #f56565;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.wysi-popover .wysi-remove-link svg {
  width: 12px;
  height: 12px;
  fill: currentColor;
}

.wysi-popover .wysi-remove-link:hover {
  background: #fff5f5;
}

.wysi-popover div button[data-action="unlink"] {
  margin: 15px auto 0 0;
  padding: 0 4px;
}

.wysi-segmented {
  display: flex;
  position: relative;
  width: 100%;
  height: 32px;
  margin: 0 0 10px 0;
  padding: 0;
  border: 1px solid #ccc;
  border-radius: 16px;
  align-items: center;
  overflow: hidden;
  outline: 2px solid transparent;
}

.wysi-segmented:focus-within {
  outline: 2px solid var(--wysi-primary);
}

.wysi-segmented legend {
  position: absolute;
  opacity: 0;
}

.wysi-segmented input {
  position: absolute;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  left: 0;
  top: 0;
  opacity: 0;
  pointer-events: none;
}

.wysi-segmented input + label {
  position: relative;
  display: block;
  margin: 0 0;
  z-index: 1;
  font-size: 0.95em;
  text-align: center;
  line-height: 32px;
  cursor: pointer;
}

.wysi-segmented input:checked + label {
  color: #333;
  background-color: var(--wysi-highlight);
}

.wysi-separator {
  width: 5px;
  height: 30px;
  margin-right: 10px;
  border-right: 1px solid #ccc;
}

.wysi-newline {
  flex-basis: 100%;
}

.wysi-editor {
  min-height: 400px;
  max-height: 80vh;
  padding: 1em;
  outline: none;
  overflow: auto;
  height: auto !important;
}

.wysi-autogrow .wysi-editor {
  max-height: calc(100svh - 200px) !important;
}

.wysi-editor > :first-child {
  margin-top: 0;
}

.wysi-editor blockquote {
  margin-left: 0;
  margin-right: 0;
  padding-left: 1.5em;
  padding-right: 1.5em;
  border-left: 3px solid #ccc;
  font-style: italic;
}

.wysi-editor img:hover,
.wysi-editor img.wysi-selected {
  outline: 3px solid #ddd;
}

.wysi-editor img:hover {
  outline-color: #bbb;
}

.wysi-wrapper:focus-within img.wysi-selected {
  outline-color: var(--wysi-primary);
}

.wysi-darkmode .wysi-toolbar {
  color: #fff;
  background-color: #222;
}

.wysi-darkmode .wysi-toolbar button:not([aria-pressed="true"]) {
  color: #ddd;
}

.wysi-darkmode .wysi-listbox button[aria-expanded="true"],
.wysi-darkmode .wysi-toolbar > button:focus,
.wysi-darkmode .wysi-toolbar > button:hover,
.wysi-darkmode .wysi-toolbar > div > button:focus,
.wysi-darkmode .wysi-toolbar > div > button:hover {
  background-color: #444;
}

.wysi-darkmode .wysi-toolbar button[aria-pressed="true"]:hover {
  background-color: var(--wysi-highlight);
  mix-blend-mode: difference;
}

.wysi-darkmode .wysi-listbox div,
.wysi-darkmode .wysi-popover div {
  background-color: #444;
}

.wysi-darkmode .wysi-listbox div button:focus {
  background-color: #222;
}

.wysi-darkmode .wysi-popover div:before {
  border-bottom-color: #444;
}

.wysi-darkmode .wysi-popover div button:not(:last-of-type):hover,
.wysi-darkmode .wysi-popover div button:not(:last-of-type):focus {
  color: #444;
}

.wysi-darkmode .wysi-separator {
  border-color: #444;
}

.wysi-autohide.wysi-darkmode:focus-within .wysi-toolbar {
  outline-color: #111;
}

/** Tables **/
.wysi-editor table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
  border: 1px solid #ddd;
}

.wysi-editor th,
.wysi-editor td {
  padding: 8px 12px;
  border: 1px solid #ddd;
  text-align: left;
}

.wysi-editor td {
  font-weight: normal !important;
}

.wysiwyg-content table {
  width: 100% !important;
  border-collapse: collapse !important;
  margin: 1rem 0 !important;
  border: 1px solid #e2e8f0 !important;
}

.wysiwyg-content th,
.wysiwyg-content td {
  padding: 0.75rem 1rem !important;
  border: 1px solid #e2e8f0 !important;
  text-align: left !important;
}

.wysiwyg-content th {
  background-color: #f8fafc !important;
  font-weight: bold !important;
}

.wysiwyg-content td {
  font-weight: normal !important;
}

/* Published Content Styling */
.wysiwyg-content {
  line-height: 1.6;
  color: #333;
  word-wrap: break-word;
  height: auto !important;
  display: block !important;
}

.wysiwyg-content::after {
  content: "";
  display: table;
  clear: both;
}

.wysiwyg-content *,
.wysi-editor * {
  font-family: inherit;
  font-size: inherit;
  max-width: 100% !important;
  box-sizing: border-box !important;
}

/* Legacy content overrides */
.wysiwyg-content .page-asset,
.wysiwyg-content .asset,
.wysi-editor .page-asset,
.wysi-editor .asset {
  width: 100% !important;
  height: auto !important;
  min-height: unset !important;
  position: relative !important;
}

/* Override problematic inline styles from legacy content */
.wysiwyg-content [style*="width: 740px"],
.wysiwyg-content [style*="width:740px"],
.wysi-editor [style*="width: 740px"],
.wysi-editor [style*="width:740px"],
.wysi-editor [style*="740px"] {
  width: 100% !important;
}

.wysiwyg-content [style*="min-height: 300px"],
.wysiwyg-content [style*="min-height:300px"],
.wysi-editor [style*="min-height: 300px"],
.wysi-editor [style*="min-height:300px"] {
  min-height: unset !important;
}

.wysiwyg-content [style*="overflow: hidden"],
.wysiwyg-content [style*="overflow:hidden"],
.wysi-editor [style*="overflow: hidden"],
.wysi-editor [style*="overflow:hidden"] {
  overflow: visible !important;
}

.wysiwyg-content h1,
.wysiwyg-content h2,
.wysiwyg-content h3,
.wysiwyg-content h4 {
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  font-weight: bold;
  line-height: 1.3;
  color: #1a202c;
}

.wysiwyg-content h1 {
  font-size: 2em;
  border-bottom: 2px solid #e2e8f0;
  padding-bottom: 0.3em;
}

.wysiwyg-content h2 {
  font-size: 1.5em;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 0.3em;
}

.wysiwyg-content h3 {
  font-size: 1.25em;
}

.wysiwyg-content h4 {
  font-size: 1.1em;
}

.wysiwyg-content p {
  margin-bottom: 1em;
}

.wysiwyg-content strong,
.wysiwyg-content b {
  font-weight: bold;
}

.wysiwyg-content em,
.wysiwyg-content i {
  font-style: italic;
}

.wysiwyg-content u {
  text-decoration: underline;
}

.wysiwyg-content s,
.wysiwyg-content strike,
.wysiwyg-content del {
  text-decoration: line-through;
}

.wysiwyg-content ul,
.wysiwyg-content ol {
  margin-bottom: 1em;
  padding-left: 2em;
}

.wysiwyg-content ul {
  list-style-type: disc !important;
}

.wysiwyg-content ol {
  list-style-type: decimal !important;
}

.wysiwyg-content li {
  margin-bottom: 0.25em;
}

.wysiwyg-content blockquote {
  margin: 1em 0;
  padding: 0.5em 1.5em;
  border-left: 4px solid #e2e8f0;
  color: #4a5568;
  font-style: italic;
}

.wysiwyg-content a,
.wysi-editor a {
  color: #3182ce !important;
  text-decoration: underline !important;
}

.wysiwyg-content a:hover,
.wysi-editor a:hover {
  color: #2b6cb0 !important;
}

.wysiwyg-content img {
  max-width: 100%;
  height: auto;
  margin: 1em 0;
}

/* video container and cover */
.video-container {
  user-select: none;
  -webkit-user-drag: none;
  display: inline-block;
  vertical-align: top;
  margin-bottom: 1em;
}

.wysi-editor .video-container {
  cursor: pointer;
  outline: 1px solid transparent;
  transition: outline 0.2s;
}

.wysi-editor .video-container:hover,
.wysi-editor .video-container.wysi-selected {
  outline: 3px solid var(--wysi-primary);
}

.wysi-editor .video-container .wysi-video-cover {
  display: block !important;
  z-index: 2;
  cursor: pointer;
}

.wysi-editor .video-container iframe {
  pointer-events: none;
}

/* Mobile responsive tables */
@media (max-width: 640px) {
  .wysiwyg-content [data-pivot-wrapper] {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    margin-bottom: 12px !important;
    border: none !important;
  }

  .wysiwyg-content table[data-pivoted] {
    width: max-content !important;
    min-width: 100% !important;
    border-collapse: collapse !important;
    outline: 1px solid #e2e8f0 !important;
    border-radius: 6px !important;
    overflow: hidden !important;
  }

  .wysiwyg-content table[data-pivoted] tbody,
  .wysiwyg-content table[data-pivoted] tr {
    display: block !important;
    width: 100% !important;
  }

  .wysiwyg-content table[data-pivoted] tr {
    display: flex !important;
    border-bottom: 1px solid #e2e8f0 !important;
  }

  .wysiwyg-content table[data-pivoted] tr:last-child {
    border-bottom: none !important;
  }

  .wysiwyg-content table[data-pivoted] th {
    display: flex !important;
    align-items: center !important;
    flex-shrink: 0 !important;
    flex-grow: 0 !important;
    width: 120px !important;
    padding: 0.6rem 0.75rem !important;
    color: #fff !important;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2) !important;
    font-weight: bold !important;
    font-size: 0.9em !important;
    border-right: 3px solid rgba(0, 0, 0, 0.15) !important;
    box-sizing: border-box !important;
    word-break: break-word !important;
  }

  .wysiwyg-content table[data-pivoted] td {
    display: flex !important;
    align-items: center !important;
    flex: 1 !important;
    min-width: 100px !important;
    padding: 0.6rem 0.75rem !important;
    box-sizing: border-box !important;
    border-right: 1px solid #e2e8f0 !important;
    word-break: break-word !important;
  }
}
