/*
 * Styling for rich text content across SimChat — shared by the Quill
 * editor (so authors get WYSIWYG) and every read-only renderer that
 * displays saved rich text (scenarios, questions, conversations, etc.).
 *
 * Historically this content was produced by CKEditor, so the selectors
 * still target CK-style markup (e.g. `figure.media` for embeds). The
 * editor continues to round-trip to that markup on save, so rules
 * written for legacy content keep working unchanged.
 */

/*
 * Quill editor styles require high specificity to override
 * In a later refactor we can put the quill styles in a layer, but for
 * now we will pepper .ql-snow.ql-container .ql-editor.simchat-rich-content everywhere...
 */

.simchat-rich-content > :first-child,
.ql-snow.ql-container .ql-editor.simchat-rich-content > :first-child {
    margin-top: 0 !important;
}

.simchat-rich-content {
    overflow-x: auto;
}

/* Typography */

.simchat-rich-content h1,
.ql-snow.ql-container .ql-editor.simchat-rich-content h1 {
    font-size: 1.625rem;
    font-weight: 600;
    margin-top: 1.5rem;
    margin-bottom: 1rem;
}

.simchat-rich-content h2,
.ql-snow.ql-container .ql-editor.simchat-rich-content h2,
.simchat-rich-content h5,
.ql-snow.ql-container .ql-editor.simchat-rich-content h5 {
    /* h5 is used as a h1 as per legacy CK rules */
    font-size: 1.375rem;
    font-weight: 600;
    margin-top: 1.35rem;
    margin-bottom: 1rem;
}

.simchat-rich-content h3,
.ql-snow.ql-container .ql-editor.simchat-rich-content h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-top: 1.2rem;
    margin-bottom: 0.75rem;
    text-decoration: underline;
}

.simchat-rich-content h4,
.ql-snow.ql-container .ql-editor.simchat-rich-content h4 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-top: 1.1rem;
    margin-bottom: 0.75rem;
    color: #0056b3;
}

.simchat-rich-content p,
.ql-snow.ql-container .ql-editor.simchat-rich-content p {
    margin-bottom: 8px;
}

.simchat-rich-content a,
.ql-snow.ql-container .ql-editor.simchat-rich-content a {
    color: #0056b3 !important;
    text-decoration: underline;
}

.simchat-rich-content a:hover,
.ql-snow.ql-container .ql-editor.simchat-rich-content a:hover {
    color: #003d82 !important;
}

.simchat-rich-content hr {
    margin-top: 5rem;
    margin-bottom: 5rem;
}

/* Lists */

.simchat-rich-content ol,
.simchat-rich-content ul {
    /* Quill handles its own list padding */
    padding-left: 32px;
}

.simchat-rich-content li {
    /* Quill handles its own list padding */
    padding-left: 10px;
}

.simchat-rich-content li,
.ql-snow.ql-container .ql-editor.simchat-rich-content li {
    margin-top: 4px;

}

.simchat-rich-content ol li::marker,
.ql-snow.ql-container .ql-editor.simchat-rich-content ol li::marker {
    font-weight: 600;
}

.simchat-rich-content ul li::marker,
.ql-snow.ql-container .ql-editor.simchat-rich-content ul li::marker {
    font-size: 19px;
    line-height: 1;
    vertical-align: middle;
}

/* Tables */

.simchat-rich-content table,
.ql-snow.ql-container .ql-editor.simchat-rich-content table {
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.875em;
    min-width: 100%;
    table-layout: auto !important;
    min-width: 100% !important;
    width: fit-content !important;
}

.simchat-rich-content table tr,
.ql-snow.ql-container .ql-editor.simchat-rich-content table tr {
    border-bottom: none !important;
}

.simchat-rich-content table p,
.ql-snow.ql-container .ql-editor.simchat-rich-content table p {
    margin-bottom: 0px;
}

.simchat-rich-content table th,
.simchat-rich-content table td,
.ql-snow.ql-container .ql-editor.simchat-rich-content table th,
.ql-snow.ql-container .ql-editor.simchat-rich-content table td {
    border: none;
    border-bottom: var(--x-border-width) solid var(--x-border-color);
    border-right: var(--x-border-width) solid var(--x-border-color);
    background-color: var(--x-secondary-bg);
    padding: 12px 8px;
    white-space: normal !important;
    width: auto !important;
    min-width: 80px;
}

.simchat-rich-content table tr:last-child td,
.ql-snow.ql-container .ql-editor.simchat-rich-content table tr:last-child td {
    border-bottom: none !important;
}

.simchat-rich-content table td:last-child,
.simchat-rich-content table th:last-child,
.ql-snow.ql-container .ql-editor.simchat-rich-content table td:last-child,
.ql-snow.ql-container .ql-editor.simchat-rich-content table th:last-child {
    border-right: none !important;
}

.simchat-rich-content table th,
.ql-snow.ql-container .ql-editor.simchat-rich-content table th {
    background-color: color-mix(in srgb, #0031cc 80%, transparent);
    color: white !important;
    font-weight: 700;
}

.simchat-rich-content table th p,
.ql-snow.ql-container .ql-editor.simchat-rich-content table th p {
    color: white !important;
}

.simchat-rich-content table th,
.ql-snow.ql-container .ql-editor.simchat-rich-content table th {
    border-color: var(--x-border-color);
}

/* Figures/Embeds */

.simchat-rich-content table,
.simchat-rich-content blockquote,
.simchat-rich-content audio,
.simchat-rich-content video,
.simchat-rich-content figure,
.ql-snow.ql-container .ql-editor.simchat-rich-content table,
.ql-snow.ql-container .ql-editor.simchat-rich-content blockquote,
.ql-snow.ql-container .ql-editor.simchat-rich-content audio,
.ql-snow.ql-container .ql-editor.simchat-rich-content video,
.ql-snow.ql-container .ql-editor.simchat-rich-content figure {
    margin-bottom: 20px;
    margin-top: 20px;
}

.simchat-rich-content video,
.simchat-rich-content figure:not(:has(table,iframe)),
.ql-snow.ql-container .ql-editor.simchat-rich-content video,
.ql-snow.ql-container .ql-editor.simchat-rich-content figure:not(:has(table,iframe)) {
    border-radius: 8px;
    border: 1px solid var(--x-border-color);
}

.simchat-rich-content img,
.ql-snow.ql-container .ql-editor.simchat-rich-content img {
    width: 100%;
}

.simchat-rich-content video,
.simchat-rich-content img,
.simchat-rich-content iframe,
.ql-snow.ql-container .ql-editor.simchat-rich-content video,
.ql-snow.ql-container .ql-editor.simchat-rich-content img,
.ql-snow.ql-container .ql-editor.simchat-rich-content iframe {
    border-radius: 8px;
}

.simchat-rich-content figcaption,
.ql-snow.ql-container .ql-editor.simchat-rich-content figcaption {
    padding: 4px 8px;
    text-align: center;
    font-size: 0.875rem;
    color: var(--x-secondary-color);
    border-top: 1px solid var(--x-border-color);
    background-color: var(--x-tertiary-bg);
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
}

.simchat-rich-content figcaption,
.ql-snow.ql-container .ql-editor.simchat-rich-content figcaption {
    outline-color: var(--brand-primary, #0031cc);
}

.simchat-rich-content img[data-has-lightbox='true'],
.ql-snow.ql-container .ql-editor.simchat-rich-content img[data-has-lightbox='true'] {
    transition: opacity 0.15s ease;
    cursor: pointer;
}

.simchat-rich-content oembed {
    background-color: var(--x-tertiary-bg) !important;
}

.simchat-rich-content img[data-has-lightbox='true']:hover,
.ql-snow.ql-container
    .ql-editor.simchat-rich-content
    img[data-has-lightbox='true']:hover {
    opacity: 0.7;
}

.simchat-rich-content blockquote,
.ql-snow.ql-container .ql-editor.simchat-rich-content blockquote {
    border-left: 4px solid var(--brand-primary, #0031cc);
    padding: 4px;
    padding-left: 12px;
    color: var(--x-secondary-color);
    font-style: italic;
    background-color: var(--x-tertiary-bg);
    border-radius: 4px;
}

.simchat-rich-content blockquote p,
.ql-snow.ql-container .ql-editor.simchat-rich-content blockquote p {
    margin-bottom: 0px;
}

/*
 * Media embeds (YouTube/Vimeo). In read-only views, render_media_embeds
 * rewrites the inner <oembed> to a responsive <div><iframe></div> pair.
 * Size belongs on that wrapper div (not the figure).
 */
.simchat-rich-content figure.media,
.ql-snow.ql-container .ql-editor.simchat-rich-content figure.media {
    margin: 1em 0;
    clear: both;
}

/* Max width overridden by inline styles from the <oembed>, which are set on the wrapper div by render_media_embeds */
.simchat-rich-content figure.media > div,
.ql-snow.ql-container .ql-editor.simchat-rich-content figure.media > div {
    position: relative;
    width: 100%;
    max-width: 480px;
}

/* Quill editor list rules (quill has its own markup for in-editor lists that needs accounting for) */

.ql-snow.ql-container .ql-editor ol,
.ql-snow.ql-container .ql-editor ul:not(.ql-table-dropdown-list) {
    margin-bottom: 16px;
}

.ql-snow.ql-container .ql-editor li {
    line-height: 1.5;
}

.ql-snow.ql-container .ql-editor ul:not(.ql-table-dropdown-list) li {
    list-style: none;
    padding-left: 1.5em;
    position: relative;
}

.ql-snow.ql-container
    .ql-editor
    ul:not(.ql-table-dropdown-list)
    li:not([data-list='bullet'])::before,
.ql-snow.ql-container
    .ql-editor
    ul:not(.ql-table-dropdown-list)
    li:not([data-list='ordered'])::before,
.ql-snow.ql-container .ql-editor li[data-list='bullet'] > span.ql-ui::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--x-body-color);
    vertical-align: middle;
    margin-bottom: 2px;
    display: inline-block;
}

.ql-snow.ql-container .ql-editor li[data-list='bullet'] > span.ql-ui::before {
    margin-left: -1.4em;
}

.ql-snow.ql-container
    .ql-editor
    ul:not(.ql-table-dropdown-list)
    li:not([data-list='bullet'])::before,
.ql-snow.ql-container
    .ql-editor
    ul:not(.ql-table-dropdown-list)
    li:not([data-list='ordered'])::before {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
}

.ql-snow.ql-container .ql-editor ol li:not([data-list='ordered'])::marker,
.ql-snow.ql-container .ql-editor ol li:not([data-list='bullet'])::marker,
.ql-snow.ql-container .ql-editor li[data-list='ordered'] > span.ql-ui::before {
    padding-right: 10px;
    font-weight: 700;
}
