/* EMS Rich Text Editor - modern document-style writing surface */

.ems-rich-editor {
    --ems-rte-accent: #0d9488;
    --ems-rte-accent-soft: rgb(13 148 136 / 0.1);
    --ems-rte-accent-strong: rgb(13 148 136 / 0.16);
    --ems-rte-border: #dbe3ee;
    --ems-rte-border-strong: #cbd5e1;
    --ems-rte-surface: #ffffff;
    --ems-rte-toolbar: #f8fafc;
    --ems-rte-text: #0f172a;
    --ems-rte-muted: #64748b;
    --ems-rte-shadow: 0 1px 2px rgb(15 23 42 / 0.04), 0 8px 24px rgb(15 23 42 / 0.04);
    --ems-rte-radius: 0.9rem;
    width: 100%;
}

.dark .ems-rich-editor {
    --ems-rte-accent: #2dd4bf;
    --ems-rte-accent-soft: rgb(45 212 191 / 0.12);
    --ems-rte-accent-strong: rgb(45 212 191 / 0.18);
    --ems-rte-border: #1e293b;
    --ems-rte-border-strong: #334155;
    --ems-rte-surface: #0b1220;
    --ems-rte-toolbar: #0f172a;
    --ems-rte-text: #e2e8f0;
    --ems-rte-muted: #94a3b8;
    --ems-rte-shadow: 0 1px 2px rgb(0 0 0 / 0.25), 0 10px 28px rgb(0 0 0 / 0.28);
}

.ems-rich-editor__label {
    display: inline-block;
    margin-bottom: 0.5rem;
}

.ems-rich-editor__surface {
    position: relative;
    width: 100%;
    min-height: 22rem;
    height: 22rem;
    border: 1px solid var(--ems-rte-border-strong);
    border-radius: var(--ems-rte-radius);
    overflow: hidden;
    resize: vertical;
    background: var(--ems-rte-surface);
    box-shadow: var(--ems-rte-shadow);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ems-rich-editor--compact .ems-rich-editor__surface {
    min-height: 16rem;
    height: 16rem;
}

.ems-rich-editor--option .ems-rich-editor__surface {
    min-height: 16rem;
    height: 16rem;
}

/* Compact chrome matches the shared header toolbar styling */
.ems-rich-editor--compact .tox .tox-editor-header {
    padding: 0.35rem 0.45rem !important;
}

.ems-rich-editor.is-focused .ems-rich-editor__surface,
.ems-rich-editor__surface.is-focused {
    border-color: var(--ems-rte-border-strong);
    box-shadow: var(--ems-rte-shadow);
}

.ems-rich-editor__surface > .tox-tinymce {
    width: 100% !important;
    height: 100% !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
}

.ems-rich-editor__textarea {
    min-height: 10rem;
    width: 100%;
}

.ems-rich-editor.is-ready .ems-rich-editor__textarea {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.ems-rich-editor__progress {
    position: absolute;
    left: 0.75rem;
    right: 0.75rem;
    bottom: 0.75rem;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 0.8rem;
    border-radius: 0.65rem;
    background: rgba(15, 23, 42, 0.92);
    color: #f8fafc;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.25);
}

.ems-rich-editor__progress[hidden] {
    display: none !important;
}

.ems-rich-editor__progress-bar {
    flex: 1;
    height: 0.4rem;
    border-radius: 999px;
    background: linear-gradient(90deg, #2dd4bf, #38bdf8);
    transform-origin: left center;
    transform: scaleX(0.05);
    transition: transform 0.15s ease;
}

.ems-rich-editor__progress-label {
    font-size: 0.75rem;
    white-space: nowrap;
}

.ems-rich-editor__codepanel {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 22rem;
    height: 100%;
    background: #0b1220;
}

.ems-rich-editor__codepanel[hidden] {
    display: none !important;
}

.ems-rich-editor__codepanel-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex: 0 0 auto;
    padding: 0.65rem 0.85rem;
    border-bottom: 1px solid #1e293b;
    background: #111827;
}

.ems-rich-editor__codepanel-title {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}

.ems-rich-editor__codepanel-title strong {
    color: #f8fafc;
    font-size: 0.85rem;
    font-weight: 650;
}

.ems-rich-editor__codepanel-title span {
    color: #94a3b8;
    font-size: 0.72rem;
}

.ems-rich-editor__codepanel-back {
    flex: 0 0 auto;
    border: 1px solid #334155;
    border-radius: 0.55rem;
    background: #0d9488;
    color: #fff;
    font-size: 0.8rem;
    font-weight: 650;
    padding: 0.45rem 0.8rem;
    cursor: pointer;
    white-space: nowrap;
}

.ems-rich-editor__codepanel-back:hover {
    background: #0f766e;
}

.ems-rich-editor__codeview {
    display: block;
    box-sizing: border-box;
    width: 100%;
    flex: 1 1 auto;
    min-height: 16rem;
    margin: 0;
    padding: 1rem 1.1rem;
    border: 0;
    outline: none;
    resize: none;
    background: #0b1220;
    color: #e2e8f0;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.85rem;
    line-height: 1.55;
    tab-size: 2;
}

.ems-rich-editor__codeview[hidden] {
    display: none !important;
}

.ems-rich-editor.is-codeview .tox-sidebar-wrap {
    display: none !important;
}

.ems-rich-editor.is-codeview .ems-rich-editor__surface {
    display: flex;
    flex-direction: column;
    min-height: 22rem;
}

.ems-rich-editor.is-codeview .tox-tinymce {
    flex: 0 0 auto !important;
    height: auto !important;
    min-height: 0 !important;
}

.dark .ems-rich-editor__codepanel,
.dark .ems-rich-editor__codeview {
    background: #020617;
}

.dark .ems-rich-editor__codepanel-bar {
    background: #0f172a;
    border-bottom-color: #1e293b;
}

/* —— Fullscreen via browser Top Layer (:fullscreen only — never class alone) —— */
.ems-rich-editor__surface:fullscreen,
.ems-rich-editor__surface:-webkit-full-screen {
    box-sizing: border-box !important;
    width: 100% !important;
    height: 100% !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    margin: 0 !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    border-radius: 0 !important;
    border: 0 !important;
    box-shadow: none !important;
    overflow: hidden !important;
    resize: none !important;
    background: #ffffff !important;
}

.ems-rich-editor__surface:fullscreen.ems-rich-editor--dark,
.ems-rich-editor__surface:-webkit-full-screen.ems-rich-editor--dark,
.dark .ems-rich-editor__surface:fullscreen,
.dark .ems-rich-editor__surface:-webkit-full-screen {
    background: #0f172a !important;
    --ems-rte-accent: #2dd4bf;
    --ems-rte-accent-soft: rgb(45 212 191 / 0.12);
    --ems-rte-accent-strong: rgb(45 212 191 / 0.18);
    --ems-rte-border: #1e293b;
    --ems-rte-border-strong: #334155;
    --ems-rte-surface: #0f172a;
    --ems-rte-toolbar: #0f172a;
    --ems-rte-text: #e2e8f0;
    --ems-rte-muted: #94a3b8;
}

.ems-rich-editor__surface:fullscreen.ems-rich-editor--light,
.ems-rich-editor__surface:-webkit-full-screen.ems-rich-editor--light {
    background: #ffffff !important;
    --ems-rte-accent: #0d9488;
    --ems-rte-accent-soft: rgb(13 148 136 / 0.1);
    --ems-rte-accent-strong: rgb(13 148 136 / 0.16);
    --ems-rte-border: #dbe3ee;
    --ems-rte-border-strong: #cbd5e1;
    --ems-rte-surface: #ffffff;
    --ems-rte-toolbar: #f8fafc;
    --ems-rte-text: #0f172a;
    --ems-rte-muted: #64748b;
}

.ems-rich-editor__surface:fullscreen > .tox-tinymce,
.ems-rich-editor__surface:-webkit-full-screen > .tox-tinymce,
.ems-rich-editor__surface:fullscreen .tox-tinymce,
.ems-rich-editor__surface:-webkit-full-screen .tox-tinymce {
    flex: 1 1 auto !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
    max-height: none !important;
    display: flex !important;
    flex-direction: column !important;
    border: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
}

.ems-rich-editor__surface:fullscreen .tox-editor-header,
.ems-rich-editor__surface:-webkit-full-screen .tox-editor-header,
.ems-rich-editor__surface:fullscreen .tox .tox-editor-header,
.ems-rich-editor__surface:-webkit-full-screen .tox .tox-editor-header {
    flex: 0 0 auto !important;
    position: relative !important;
    top: auto !important;
    z-index: 5 !important;
}

.ems-rich-editor__surface:fullscreen .tox-editor-container,
.ems-rich-editor__surface:-webkit-full-screen .tox-editor-container,
.ems-rich-editor__surface:fullscreen .tox-sidebar-wrap,
.ems-rich-editor__surface:-webkit-full-screen .tox-sidebar-wrap {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: auto !important;
    display: flex !important;
    flex-direction: column !important;
    background: transparent !important;
}

.ems-rich-editor__surface:fullscreen .tox-sidebar-wrap,
.ems-rich-editor__surface:-webkit-full-screen .tox-sidebar-wrap {
    overflow: hidden !important;
}

.ems-rich-editor__surface:fullscreen .tox-edit-area,
.ems-rich-editor__surface:-webkit-full-screen .tox-edit-area {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: auto !important;
    display: flex !important;
    flex-direction: column !important;
    background: #ffffff !important;
}

.ems-rich-editor__surface:fullscreen.ems-rich-editor--dark .tox-edit-area,
.ems-rich-editor__surface:-webkit-full-screen.ems-rich-editor--dark .tox-edit-area,
.dark .ems-rich-editor__surface:fullscreen .tox-edit-area,
.dark .ems-rich-editor__surface:-webkit-full-screen .tox-edit-area {
    background: #0f172a !important;
}

.ems-rich-editor__surface:fullscreen .tox-edit-area__iframe,
.ems-rich-editor__surface:-webkit-full-screen .tox-edit-area__iframe {
    flex: 1 1 auto !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
    border: 0 !important;
    background: #ffffff !important;
}

.ems-rich-editor__surface:fullscreen.ems-rich-editor--dark .tox-edit-area__iframe,
.ems-rich-editor__surface:-webkit-full-screen.ems-rich-editor--dark .tox-edit-area__iframe,
.dark .ems-rich-editor__surface:fullscreen .tox-edit-area__iframe,
.dark .ems-rich-editor__surface:-webkit-full-screen .tox-edit-area__iframe {
    background: #0f172a !important;
}

/* Menus / dialogs parked inside the fullscreen surface — fixed overlay sink
   (must NOT participate in the surface flex layout or dropdowns get clipped). */
.ems-rich-editor__surface:fullscreen,
.ems-rich-editor__surface:-webkit-full-screen {
    overflow: visible !important;
}

.ems-rich-editor__surface:fullscreen > .tox-tinymce,
.ems-rich-editor__surface:-webkit-full-screen > .tox-tinymce {
    overflow: hidden !important;
}

.ems-rich-editor__surface:fullscreen .tox-tinymce-aux,
.ems-rich-editor__surface:-webkit-full-screen .tox-tinymce-aux,
.ems-rich-editor__surface:fullscreen .tox-silver-sink,
.ems-rich-editor__surface:-webkit-full-screen .tox-silver-sink,
.ems-rich-editor__surface:fullscreen .ems-rte-fs-sink,
.ems-rich-editor__surface:-webkit-full-screen .ems-rte-fs-sink,
.ems-rich-editor__surface:fullscreen .tox-dialog-wrap,
.ems-rich-editor__surface:-webkit-full-screen .tox-dialog-wrap {
    position: fixed !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    max-height: none !important;
    margin: 0 !important;
    flex: none !important;
    align-self: stretch !important;
    overflow: visible !important;
    pointer-events: none !important;
    z-index: 2147483000 !important;
}

.ems-rich-editor__surface:fullscreen .tox-tinymce-aux > *,
.ems-rich-editor__surface:-webkit-full-screen .tox-tinymce-aux > *,
.ems-rich-editor__surface:fullscreen .tox-silver-sink > *,
.ems-rich-editor__surface:-webkit-full-screen .tox-silver-sink > *,
.ems-rich-editor__surface:fullscreen .ems-rte-fs-sink > *,
.ems-rich-editor__surface:-webkit-full-screen .ems-rte-fs-sink > *,
.ems-rich-editor__surface:fullscreen .tox-dialog-wrap,
.ems-rich-editor__surface:-webkit-full-screen .tox-dialog-wrap,
.ems-rich-editor__surface:fullscreen .tox-menu,
.ems-rich-editor__surface:-webkit-full-screen .tox-menu,
.ems-rich-editor__surface:fullscreen .tox-collection,
.ems-rich-editor__surface:-webkit-full-screen .tox-collection,
.ems-rich-editor__surface:fullscreen .tox-dialog,
.ems-rich-editor__surface:-webkit-full-screen .tox-dialog,
.ems-rich-editor__surface:fullscreen .tox-dialog__busy-spinner,
.ems-rich-editor__surface:-webkit-full-screen .tox-dialog__busy-spinner {
    pointer-events: auto !important;
}

.ems-rich-editor__surface:fullscreen .tox-menu,
.ems-rich-editor__surface:-webkit-full-screen .tox-menu,
.ems-rich-editor__surface:fullscreen .tox-selected-menu,
.ems-rich-editor__surface:-webkit-full-screen .tox-selected-menu,
.ems-rich-editor__surface:fullscreen .tox-collection--list,
.ems-rich-editor__surface:-webkit-full-screen .tox-collection--list {
    z-index: 2147483646 !important;
    overflow: auto !important;
    max-height: min(60vh, 360px) !important;
}

/* —— Editor shell —— */
.ems-rich-editor--header .tox-tinymce,
.ems-rich-editor--compact .tox-tinymce {
    border: 0 !important;
    border-radius: 0 !important;
    overflow: visible !important;
    width: 100% !important;
    box-shadow: none !important;
    background: transparent !important;
}

.ems-rich-editor--header .tox .tox-editor-header,
.ems-rich-editor--compact .tox .tox-editor-header {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    transform: none !important;
    pointer-events: auto !important;
    position: relative !important;
    border-bottom: 1px solid var(--ems-rte-border) !important;
    background: var(--ems-rte-toolbar) !important;
    padding: 0.35rem 0.45rem !important;
    box-shadow: none !important;
    row-gap: 0.2rem !important;
}

.ems-rich-editor--header .tox .tox-toolbar,
.ems-rich-editor--header .tox .tox-toolbar__primary,
.ems-rich-editor--header .tox .tox-toolbar-overlord,
.ems-rich-editor--compact .tox .tox-toolbar,
.ems-rich-editor--compact .tox .tox-toolbar__primary,
.ems-rich-editor--compact .tox .tox-toolbar-overlord {
    display: flex !important;
    align-items: center !important;
    flex-wrap: wrap !important;
    background: transparent !important;
}

.ems-rich-editor--header .tox .tox-toolbar-overlord,
.ems-rich-editor--compact .tox .tox-toolbar-overlord {
    width: 100% !important;
}

.ems-rich-editor--header .tox .tox-toolbar__group,
.ems-rich-editor--compact .tox .tox-toolbar__group {
    padding: 0 0.15rem !important;
}

.ems-rich-editor--header .tox .tox-tbtn,
.ems-rich-editor--compact .tox .tox-tbtn,
.ems-rich-editor--header .tox .tox-split-button,
.ems-rich-editor--compact .tox .tox-split-button {
    border-radius: 0.45rem !important;
    margin: 0.05rem !important;
    min-width: 2rem !important;
    height: 2rem !important;
    color: var(--ems-rte-text) !important;
}

.ems-rich-editor--header .tox .tox-tbtn svg,
.ems-rich-editor--compact .tox .tox-tbtn svg {
    fill: currentColor !important;
}

.ems-rich-editor--header .tox .tox-tbtn:hover,
.ems-rich-editor--compact .tox .tox-tbtn:hover,
.ems-rich-editor--header .tox .tox-split-button:hover,
.ems-rich-editor--compact .tox .tox-split-button:hover {
    background: var(--ems-rte-accent-soft) !important;
}

.ems-rich-editor--header .tox .tox-tbtn:focus-visible,
.ems-rich-editor--compact .tox .tox-tbtn:focus-visible {
    outline: 2px solid var(--ems-rte-accent) !important;
    outline-offset: 1px !important;
}

.ems-rich-editor--header .tox .tox-tbtn--enabled,
.ems-rich-editor--compact .tox .tox-tbtn--enabled,
.ems-rich-editor--header .tox .tox-tbtn--enabled:hover,
.ems-rich-editor--compact .tox .tox-tbtn--enabled:hover {
    background: var(--ems-rte-accent-strong) !important;
    color: var(--ems-rte-accent) !important;
}

.ems-rich-editor--header .tox .tox-tbtn--select,
.ems-rich-editor--compact .tox .tox-tbtn--select {
    min-width: 3.75rem !important;
    max-width: 7.5rem !important;
    padding-inline: 0.35rem !important;
    font-size: 0.78rem !important;
    font-weight: 550 !important;
}

.ems-rich-editor--header .tox .tox-listboxfield .tox-listbox--select,
.ems-rich-editor--compact .tox .tox-listboxfield .tox-listbox--select {
    border-radius: 0.45rem !important;
    border-color: transparent !important;
    background: transparent !important;
    min-height: 2rem !important;
}

.ems-rich-editor--header .tox .tox-listboxfield .tox-listbox--select:hover,
.ems-rich-editor--compact .tox .tox-listboxfield .tox-listbox--select:hover {
    background: var(--ems-rte-accent-soft) !important;
}

.ems-rich-editor--header .tox .tox-statusbar,
.ems-rich-editor--compact .tox .tox-statusbar {
    display: none !important;
}

.ems-rich-editor--compact .tox .tox-editor-header {
    padding: 0.25rem 0.3rem !important;
}

.ems-rich-editor--header .tox .tox-toolbar__overflow,
.ems-rich-editor--compact .tox .tox-toolbar__overflow {
    background: var(--ems-rte-toolbar) !important;
    border: 1px solid var(--ems-rte-border-strong) !important;
    border-radius: 0.75rem !important;
    box-shadow: 0 14px 36px rgb(15 23 42 / 0.14) !important;
    padding: 0.3rem !important;
}

.dark .ems-rich-editor--header .tox .tox-toolbar__overflow,
.dark .ems-rich-editor--compact .tox .tox-toolbar__overflow {
    box-shadow: 0 16px 40px rgb(0 0 0 / 0.45) !important;
}

/* —— Floating popups / menus —— */
.tox-tinymce-aux .tox-pop {
    z-index: 200020 !important;
}

.tox-tinymce-aux .tox-menu,
.tox-tinymce-aux .tox-collection--list,
.tox-tinymce-aux .tox-autocompleter,
.tox-tinymce-aux .tox-selected-menu {
    border-radius: 0.85rem !important;
    border: 1px solid #e2e8f0 !important;
    box-shadow: 0 18px 48px rgba(15, 23, 42, 0.16) !important;
    overflow: hidden;
    padding: 0.25rem !important;
}

/* Custom color picker expands inside the swatches menu — do not clip it. */
.tox-tinymce-aux .tox-swatches-menu {
    border-radius: 0.85rem !important;
    border: 1px solid #e2e8f0 !important;
    box-shadow: 0 18px 48px rgba(15, 23, 42, 0.16) !important;
    overflow: visible !important;
    padding: 0.35rem !important;
    max-height: none !important;
}

.tox-tinymce-aux .tox-swatches,
.tox-tinymce-aux .tox-swatches__picker-wrap,
.tox-tinymce-aux .tox-sv-palette,
.tox-tinymce-aux .tox-hue-slider,
.tox-tinymce-aux .tox-rgb-form {
    overflow: visible !important;
}

.tox-tinymce-aux .tox-swatches__row {
    flex-wrap: wrap;
}

.dark .tox-tinymce-aux .tox-menu,
.dark .tox-tinymce-aux .tox-collection--list,
.dark .tox-tinymce-aux .tox-autocompleter,
.dark .tox-tinymce-aux .tox-selected-menu {
    border-color: #334155 !important;
    background: #0f172a !important;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5) !important;
}

.dark .tox-tinymce-aux .tox-swatches-menu {
    border-color: #334155 !important;
    background: #0f172a !important;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5) !important;
}

.tox-tinymce-aux .tox-pop .tox-toolbar,
.tox-tinymce-aux .tox-pop .tox-toolbar__primary {
    border-radius: 0.75rem !important;
    border: 1px solid #e2e8f0 !important;
    background: #ffffff !important;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.16) !important;
    padding: 0.25rem !important;
}

.dark .tox-tinymce-aux .tox-pop .tox-toolbar,
.dark .tox-tinymce-aux .tox-pop .tox-toolbar__primary {
    border-color: #334155 !important;
    background: #0f172a !important;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45) !important;
}

.tox-tinymce-aux .tox-collection__item {
    border-radius: 0.5rem !important;
    margin: 0.1rem 0.15rem !important;
    min-height: 2rem !important;
    color: #0f172a !important;
}

.tox-tinymce-aux .tox-collection__item .tox-collection__item-label,
.tox-tinymce-aux .tox-collection__item .tox-collection__item-accessory {
    color: inherit !important;
}

.tox-tinymce-aux .tox-collection__item--active,
.tox-tinymce-aux .tox-collection__item:hover,
.tox-tinymce-aux .tox-collection__item--enabled {
    background: rgba(13, 148, 136, 0.14) !important;
    color: #0f172a !important;
}

.tox-tinymce-aux .tox-collection__item--active .tox-collection__item-label,
.tox-tinymce-aux .tox-collection__item:hover .tox-collection__item-label,
.tox-tinymce-aux .tox-collection__item--enabled .tox-collection__item-label,
.tox-tinymce-aux .tox-collection__item--active .tox-collection__item-accessory,
.tox-tinymce-aux .tox-collection__item:hover .tox-collection__item-accessory,
.tox-tinymce-aux .tox-collection__item--enabled .tox-collection__item-accessory {
    color: #0f172a !important;
}

.dark .tox-tinymce-aux .tox-collection__item {
    color: #e2e8f0 !important;
}

.dark .tox-tinymce-aux .tox-collection__item--active,
.dark .tox-tinymce-aux .tox-collection__item:hover,
.dark .tox-tinymce-aux .tox-collection__item--enabled {
    background: rgba(45, 212, 191, 0.16) !important;
    color: #f8fafc !important;
}

.dark .tox-tinymce-aux .tox-collection__item--active .tox-collection__item-label,
.dark .tox-tinymce-aux .tox-collection__item:hover .tox-collection__item-label,
.dark .tox-tinymce-aux .tox-collection__item--enabled .tox-collection__item-label,
.dark .tox-tinymce-aux .tox-collection__item--active .tox-collection__item-accessory,
.dark .tox-tinymce-aux .tox-collection__item:hover .tox-collection__item-accessory,
.dark .tox-tinymce-aux .tox-collection__item--enabled .tox-collection__item-accessory {
    color: #f8fafc !important;
}

/* Keep context toolbars near the caret instead of far-right on wide nodes */
.tox-tinymce-aux .tox-pop {
    max-width: min(92vw, 28rem);
}

.tox-tinymce-aux .tox-pop__dialog {
    margin-left: 0 !important;
}

.tox.tox-tinymce.tox-fullscreen,
.tox-fullscreen {
    z-index: 200000 !important;
}

.tox-tinymce-aux {
    z-index: 200010 !important;
}

html.ems-editor-fullscreen,
html.ems-editor-fullscreen body {
    overflow: hidden !important;
}

html.ems-editor-fullscreen #panel-root,
html.ems-editor-fullscreen #panel-content,
html.ems-editor-fullscreen #panel-main,
html.ems-editor-fullscreen .exam-create-layout,
html.ems-editor-fullscreen .exam-create-main {
    overflow: visible !important;
    transform: none !important;
    filter: none !important;
    perspective: none !important;
}

#ems-toast-root {
    z-index: 210000 !important;
}

@media (max-width: 768px) {
    .ems-rich-editor--header .tox .tox-editor-header,
    .ems-rich-editor--compact .tox .tox-editor-header {
        padding: 0.25rem 0.3rem !important;
    }

    .ems-rich-editor--header .tox .tox-tbtn,
    .ems-rich-editor--compact .tox .tox-tbtn {
        min-width: 1.85rem !important;
        height: 1.85rem !important;
    }
}

/* Content display — readable article typography (no Tailwind Typography dependency) */
.ems-rich-content {
    overflow-wrap: anywhere;
    font-size: 1.015rem;
    line-height: 1.75;
    color: #334155;
}

.dark .ems-rich-content {
    color: #cbd5e1;
}

.ems-rich-content > *:first-child {
    margin-top: 0 !important;
}

.ems-rich-content > *:last-child {
    margin-bottom: 0 !important;
}

.ems-rich-content h1,
.ems-rich-content h2,
.ems-rich-content h3,
.ems-rich-content h4,
.ems-rich-content h5,
.ems-rich-content h6 {
    color: #0f172a;
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: -0.02em;
    margin: 1.75rem 0 0.75rem;
}

.dark .ems-rich-content h1,
.dark .ems-rich-content h2,
.dark .ems-rich-content h3,
.dark .ems-rich-content h4,
.dark .ems-rich-content h5,
.dark .ems-rich-content h6 {
    color: #f8fafc;
}

.ems-rich-content h1 { font-size: 1.75rem; }
.ems-rich-content h2 { font-size: 1.4rem; margin-top: 2rem; }
.ems-rich-content h3 { font-size: 1.2rem; font-weight: 650; }
.ems-rich-content h4 { font-size: 1.05rem; font-weight: 650; }
.ems-rich-content h5,
.ems-rich-content h6 { font-size: 0.95rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; color: #64748b; }

.dark .ems-rich-content h5,
.dark .ems-rich-content h6 {
    color: #94a3b8;
}

.ems-rich-content p {
    margin: 0 0 1.1rem;
}

.ems-rich-content a {
    color: #4f46e5;
    text-decoration: underline;
    text-underline-offset: 3px;
    font-weight: 500;
}

.dark .ems-rich-content a {
    color: #a5b4fc;
}

.ems-rich-content strong,
.ems-rich-content b {
    font-weight: 700;
    color: #0f172a;
}

.dark .ems-rich-content strong,
.dark .ems-rich-content b {
    color: #f1f5f9;
}

.ems-rich-content em,
.ems-rich-content i {
    font-style: italic;
}

.ems-rich-content ul,
.ems-rich-content ol {
    margin: 0 0 1.15rem;
    padding-left: 1.35rem;
    list-style: revert;
}

.ems-rich-content ul { list-style-type: disc; }
.ems-rich-content ol { list-style-type: decimal; }

.ems-rich-content li {
    margin: 0.35rem 0;
    padding-left: 0.2rem;
}

.ems-rich-content li > p {
    margin: 0.25rem 0;
}

.ems-rich-content blockquote {
    margin: 1.25rem 0;
    padding: 0.85rem 1rem 0.85rem 1.15rem;
    border-left: 3px solid #818cf8;
    background: #f8fafc;
    border-radius: 0 0.65rem 0.65rem 0;
    color: #475569;
    font-style: italic;
}

.dark .ems-rich-content blockquote {
    background: rgba(30, 41, 59, 0.55);
    color: #94a3b8;
    border-left-color: #6366f1;
}

.ems-rich-content hr {
    margin: 1.75rem 0;
    border: 0;
    border-top: 1px solid #e2e8f0;
}

.dark .ems-rich-content hr {
    border-top-color: #334155;
}

.ems-rich-content code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.875em;
    padding: 0.15em 0.4em;
    border-radius: 0.35rem;
    background: #f1f5f9;
    color: #be123c;
}

.dark .ems-rich-content code {
    background: #1e293b;
    color: #fda4af;
}

.ems-rich-content pre {
    margin: 1.15rem 0;
    padding: 1rem 1.15rem;
    overflow-x: auto;
    border-radius: 0.75rem;
    background: #0f172a;
    color: #e2e8f0;
    font-size: 0.875rem;
    line-height: 1.6;
}

.ems-rich-content pre code {
    padding: 0;
    background: transparent;
    color: inherit;
    font-size: inherit;
}

.ems-rich-content img,
.ems-rich-content video {
    max-width: 100%;
    height: auto;
    border-radius: 0.75rem;
}

.ems-rich-content img.ems-img-inline,
.ems-rich-content img.ems-shape,
.ems-rich-content p img,
.ems-rich-content li img,
.ems-rich-content td img,
.ems-rich-content th img {
    display: inline !important;
    vertical-align: middle !important;
    margin: 0 0.4em !important;
    max-width: min(100%, 280px);
}

.ems-rich-content .ems-shape-box {
    position: relative;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    margin: 0.25em 0.4em;
    min-width: 88px;
    min-height: 56px;
    padding: 0.55em 0.85em;
    box-sizing: border-box;
    text-align: center;
    font-weight: 600;
    line-height: 1.35;
    max-width: 100%;
}

.ems-rich-content .ems-shape-box[data-ems-align="left"] {
    text-align: left !important;
    justify-content: flex-start !important;
}

.ems-rich-content .ems-shape-box[data-ems-align="center"] {
    text-align: center !important;
    justify-content: center !important;
}

.ems-rich-content .ems-shape-box[data-ems-align="right"] {
    text-align: right !important;
    justify-content: flex-end !important;
}

.ems-rich-content .ems-shape-box[data-ems-align="justify"] {
    text-align: justify !important;
    justify-content: stretch !important;
}

.ems-rich-content .ems-shape-box__text {
    display: block;
    width: 100%;
    outline: none;
    word-break: break-word;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.ems-rich-content .ems-shape-resize-handle {
    display: none !important;
}

.ems-rich-content .ems-shape-box--rectangle { border-radius: 6px; min-width: 120px; }
.ems-rich-content .ems-shape-box--rounded { border-radius: 18px; min-width: 120px; }
.ems-rich-content .ems-shape-box--circle {
    border-radius: 50%;
    width: 96px;
    height: 96px;
    min-width: 96px;
    min-height: 96px;
}
.ems-rich-content .ems-shape-box--ellipse {
    border-radius: 50%;
    min-width: 140px;
    min-height: 72px;
}
.ems-rich-content .ems-shape-box--triangle {
    clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
    border: 0 !important;
    min-width: 110px;
    min-height: 96px;
    padding-top: 1.6em;
}
.ems-rich-content .ems-shape-box--line {
    min-width: 140px;
    min-height: 12px;
    height: 12px;
    padding: 0;
    border-radius: 999px;
}
.ems-rich-content .ems-shape-box--line .ems-shape-box__text { display: none; }
.ems-rich-content .ems-shape-box--arrow {
    clip-path: polygon(0 28%, 68% 28%, 68% 0, 100% 50%, 68% 100%, 68% 72%, 0 72%);
    border: 0 !important;
    min-width: 150px;
    min-height: 48px;
}
.ems-rich-content .ems-shape-box--star {
    clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
    border: 0 !important;
    width: 96px;
    height: 96px;
    min-width: 96px;
    min-height: 96px;
}

.ems-rich-content video {
    display: block;
    margin: 1.15rem 0;
}

.ems-rich-content figure {
    margin: 1.25rem 0;
}

.ems-rich-content figcaption {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: #64748b;
    text-align: center;
}

.dark .ems-rich-content figcaption {
    color: #94a3b8;
}

.ems-rich-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.15rem 0;
    font-size: 0.95rem;
}

.ems-rich-content table th,
.ems-rich-content table td {
    border: 1px solid #cbd5e1;
    padding: 0.55rem 0.75rem;
    text-align: left;
}

.ems-rich-content table th {
    background: #f8fafc;
    font-weight: 650;
    color: #0f172a;
}

.dark .ems-rich-content table th,
.dark .ems-rich-content table td {
    border-color: #475569;
}

.dark .ems-rich-content table th {
    background: #1e293b;
    color: #f8fafc;
}

.ems-rich-content table.ems-table-bordered th,
.ems-rich-content table.ems-table-bordered td {
    border-width: 2px;
}

.ems-rich-content table.ems-table-striped tr:nth-child(even) td {
    background: #f8fafc;
}

.dark .ems-rich-content table.ems-table-striped tr:nth-child(even) td {
    background: rgba(30, 41, 59, 0.65);
}

.ems-rich-content table.ems-table-minimal th,
.ems-rich-content table.ems-table-minimal td {
    border: 0;
    border-bottom: 1px solid #e2e8f0;
}

.dark .ems-rich-content table.ems-table-minimal th,
.dark .ems-rich-content table.ems-table-minimal td {
    border-bottom-color: #334155;
}

.ems-rich-content table.ems-table-modern {
    border: 0;
    border-radius: 0.75rem;
    overflow: hidden;
    box-shadow: 0 0 0 1px #e2e8f0;
}

.ems-rich-content table.ems-table-modern th,
.ems-rich-content table.ems-table-modern td {
    border: 0;
    border-bottom: 1px solid #e2e8f0;
}

.ems-rich-content table.ems-table-modern th {
    background: #0d9488;
    color: #fff;
}

.dark .ems-rich-content table.ems-table-modern {
    box-shadow: 0 0 0 1px #334155;
}

.ems-rich-content table.ems-table-compact th,
.ems-rich-content table.ems-table-compact td {
    padding: 0.3rem 0.5rem;
    font-size: 0.9em;
}

.ems-rich-content ul[data-ems-checklist] {
    list-style: none;
    padding-left: 0.25rem;
}

.ems-rich-content ul[data-ems-checklist] li {
    position: relative;
    padding-left: 1.75rem;
    margin: 0.35rem 0;
}

.ems-rich-content ul[data-ems-checklist] li::before {
    content: '☐';
    position: absolute;
    left: 0;
    top: 0;
}

.ems-rich-content ul[data-ems-checklist] li[data-checked="true"]::before {
    content: '☑';
}

.ems-rich-content .ems-attachment-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35em;
    padding: 0.35em 0.65em;
    border-radius: 0.5rem;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    text-decoration: none !important;
    font-weight: 600;
    color: #0f766e;
}

.dark .ems-rich-content .ems-attachment-link {
    background: #1e293b;
    border-color: #334155;
    color: #5eead4;
}

/* Image adjust modal */
.ems-image-adjust__icon {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 2rem;
    height: 2rem;
    padding: 0 !important;
    border: 0;
    border-radius: 999px;
    background: transparent;
    line-height: 0;
    cursor: pointer;
    color: inherit;
}

.ems-image-adjust__icon svg {
    display: block;
    width: 1rem;
    height: 1rem;
}

body.ems-image-adjust-open {
    overflow: hidden;
}

.ems-image-adjust {
    position: fixed;
    inset: 0;
    z-index: 205000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgb(2 6 23 / 0.72);
    backdrop-filter: blur(4px);
}

.ems-image-adjust__dialog {
    width: min(920px, 100%);
    max-height: min(92vh, 860px);
    overflow: auto;
    border-radius: 1rem;
    background: #fff;
    box-shadow: 0 25px 60px rgb(0 0 0 / 0.4);
}

.dark .ems-image-adjust__dialog {
    background: rgb(15 23 42);
    color: #e2e8f0;
}

.ems-image-adjust__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgb(226 232 240);
}

.dark .ems-image-adjust__header {
    border-color: rgb(51 65 85);
}

.ems-image-adjust__header h3 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
}

.ems-image-adjust__header p {
    margin: 0.25rem 0 0;
    font-size: 0.8rem;
    color: #64748b;
}

.ems-image-adjust__stage {
    height: min(52vh, 420px);
    background: #0f172a;
    overflow: hidden;
}

.ems-image-adjust__stage img {
    display: block;
    max-width: 100%;
}

.ems-image-adjust__toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgb(226 232 240);
}

.dark .ems-image-adjust__toolbar {
    border-color: rgb(51 65 85);
}

.ems-image-adjust__toolbar button {
    border: 1px solid rgb(203 213 225);
    background: #fff;
    border-radius: 0.5rem;
    padding: 0.35rem 0.65rem;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    color: #334155;
}

.dark .ems-image-adjust__toolbar button {
    background: rgb(30 41 59);
    border-color: rgb(51 65 85);
    color: #e2e8f0;
}

.ems-image-adjust__toolbar button.is-active {
    border-color: #0d9488;
    color: #0d9488;
}

.ems-image-adjust__sep {
    width: 1px;
    align-self: stretch;
    background: rgb(203 213 225);
    margin: 0 0.25rem;
}

.ems-image-adjust__footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 1rem 1.25rem;
}

.ems-image-adjust__btn {
    border: 1px solid rgb(203 213 225);
    background: #fff;
    border-radius: 0.65rem;
    padding: 0.55rem 0.9rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    color: #334155;
}

.dark .ems-image-adjust__btn {
    background: rgb(30 41 59);
    border-color: rgb(51 65 85);
    color: #e2e8f0;
}

.ems-image-adjust__btn--primary {
    background: #0d9488;
    border-color: #0d9488;
    color: #fff;
}

.dark .ems-image-adjust__btn--primary {
    background: #14b8a6;
    border-color: #14b8a6;
    color: #042f2e;
}

