/* GP5's global stylesheet doesn't reset button chrome the way this component's markup assumes
   (it was originally written against IAM's own theme.css, which does this site-wide there) — a
   raw <button> gets the browser's default grey/bordered UA style otherwise, which is what was
   showing up instead of the intended flat toolbar buttons. Scoped to the component's own class
   prefix (attribute selector, not a descendant selector) rather than reset globally, since some
   of RichText's own elements (the link popover, the HTML-source modal) are appended straight to
   <body> for fixed positioning, not nested under .i-richtext. */
[class*="i-richtext-"], [class*="i-richtext-"]::before, [class*="i-richtext-"]::after, .i-richtext {
    box-sizing: border-box;
}
button[class*="i-richtext-"] {
    cursor: pointer;
    background: none;
    border: none;
    font: inherit;
    color: inherit;
}
[class*="i-richtext-"] input, [class*="i-richtext-"] textarea, [class*="i-richtext-"] select,
input[class*="i-richtext-"], textarea[class*="i-richtext-"] {
    font: inherit;
    color: inherit;
}

.i-richtext {
    border: 1px solid #e9ecef;
    border-radius: 12px;
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(20,19,59,0.06), 0 1px 3px rgba(20,19,59,0.08);
    overflow: hidden;
    transition: border-color 240ms cubic-bezier(0.22, 1, 0.36, 1), box-shadow 240ms cubic-bezier(0.22, 1, 0.36, 1);
}

.i-richtext-focused {
    border-color: #2f74ff;
    box-shadow: 0 0 0 4px rgba(5,84,242,0.30);
}

.i-richtext-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.25rem;
    padding: 0.6rem 0.7rem;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
}

.i-richtext-sep {
    width: 1px;
    align-self: stretch;
    margin: 0.25rem 0.4rem;
    background: #e9ecef;
}

.i-richtext-tool {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.6rem;
    height: 2.6rem;
    border-radius: 8px;
    color: #313131;
    transition: background 140ms cubic-bezier(0.22, 1, 0.36, 1), color 140ms cubic-bezier(0.22, 1, 0.36, 1);
}
.i-richtext-tool:hover { background: #f8f9fa; }
.i-richtext-tool[aria-pressed="true"] { background: #0554f2; color: #ffffff; }
.i-richtext-tool:disabled { opacity: 0.35; cursor: default; }
.i-richtext-tool:disabled:hover { background: transparent; }
.i-richtext-tool-ico { font-size: 1.4rem; line-height: 1; }

.i-richtext-dropdown { position: relative; display: inline-flex; }

.i-richtext-font-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    height: 2.6rem;
    padding: 0 0.7rem;
    border-radius: 8px;
    color: #313131;
    min-width: 7.5rem;
}
.i-richtext-font-btn:hover { background: #f8f9fa; }
.i-richtext-font-lbl { font-size: 1rem; white-space: nowrap; }
.i-richtext-font-caret { font-size: 1rem; opacity: 0.7; }

.i-richtext-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 30;
    min-width: 9rem;
    padding: 0.35rem;
    background: #ffffff;
    border: 1px solid #e9ecef;
    border-radius: 12px;
    box-shadow: 0 6px 18px rgba(20,19,59,0.10), 0 2px 6px rgba(20,19,59,0.06);
}
.i-richtext-menu-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.6rem 0.7rem;
    border-radius: 8px;
    font-size: 1.1rem;
    color: #14133b;
}
.i-richtext-menu-item:hover { background: #f8f9fa; }

.i-richtext-size { display: inline-flex; align-items: center; gap: 0.1rem; }
.i-richtext-size-val {
    min-width: 2.2rem;
    text-align: center;
    font-size: 1rem;
    font-variant-numeric: tabular-nums;
    color: #313131;
}

.i-richtext-color { position: relative; flex-direction: column; gap: 0; overflow: hidden; cursor: pointer; }
.i-richtext-color .i-richtext-tool-ico { margin-top: -1px; }
.i-richtext-color-bar {
    display: block;
    width: 1.4rem;
    height: 4px;
    border-radius: 2px;
    margin-top: 1px;
    background: #14133b;
}

.i-richtext-color-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    border: 0;
    padding: 0;
    cursor: pointer;
}

.i-richtext-popover {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    left: auto;
    z-index: 30;
    max-width: min(92vw, 30rem);
    padding: 0.5rem;
    background: #ffffff;
    border: 1px solid #e9ecef;
    border-radius: 12px;
    box-shadow: 0 6px 18px rgba(20,19,59,0.10), 0 2px 6px rgba(20,19,59,0.06);
}
.i-richtext-popover-link { display: flex; gap: 0.4rem; align-items: center; }
.i-richtext-link-input {
    width: 15rem;
    padding: 0.5rem 0.65rem;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    background: #ffffff;
}
.i-richtext-link-ok {
    padding: 0.5rem 0.8rem;
    border-radius: 8px;
    background: #0554f2;
    color: #ffffff;
    font-weight: 600;
}
.i-richtext-link-ok:hover { background: #2f74ff; }

.i-richtext-popover-chars {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 0.15rem;
    max-width: 17rem;
}
.i-richtext-char {
    width: 1.9rem;
    height: 1.9rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 1.15rem;
    line-height: 1;
}
.i-richtext-char:hover { background: #f8f9fa; }

.i-richtext-link-ok-ghost {
    background: transparent;
    color: #313131;
    box-shadow: inset 0 0 0 1.5px #e9ecef;
}
.i-richtext-link-ok-ghost:hover { background: #f8f9fa; }

.i-richtext-htmlmodal {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}
.i-richtext-htmlmodal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(6,35,26,0.55);
    backdrop-filter: blur(2px);
}
.i-richtext-htmlmodal-dialog {
    position: relative;
    width: 100%;
    max-width: 820px;
    max-height: calc(100dvh - 3rem);
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border-radius: 18px;
    box-shadow: 0 24px 60px rgba(20,19,59,0.22), 0 8px 24px rgba(20,19,59,0.14);
    padding: 1.25rem;
}
.i-richtext-htmlmodal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}
.i-richtext-htmlmodal-title { font-size: 1.1rem; color: #14133b; }
.i-richtext-htmlmodal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    color: #868686;
}
.i-richtext-htmlmodal-close .fa { font-size: 1.15rem; }
.i-richtext-htmlmodal-close:hover { color: #dc3545; background: #eef1f4; }
.i-richtext-htmlmodal-area {
    flex: 1;
    min-height: 40vh;
    resize: vertical;
    padding: 0.75rem 0.85rem;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    background: #ffffff;
    color: #14133b;
    font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
    font-size: 0.82rem;
    line-height: 1.5;
    white-space: pre;
    tab-size: 2;
}
.i-richtext-htmlmodal-foot {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 0.9rem;
}

.i-richtext-surface {
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-gutter: stable;
    background: #ffffff;
    cursor: text;
}
.i-richtext-canvas { display: block; width: 100%; }

.i-richtext-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    padding: 0;
    border: 0;
    margin: 0;
    resize: none;
    overflow: hidden;
    white-space: pre;
    opacity: 0;
    pointer-events: none;
    caret-color: transparent;
    color: transparent;
    background: transparent;
}

/* ---------- RichTextView: read-only document display ----------
   Also loaded inside a Shadow DOM by RichTextView.js's _Build() (:host then targets the shadow
   host itself) — everything else is scoped under .i-richtext-view rather than left as bare tag
   selectors, so loading this same stylesheet in the main document (via Include.php, alongside
   the editor rules above) can't leak onto every <a>/<hr>/<ul> on every GP5 page. */
:host { display: block; }

:host,
.i-richtext-view {
    font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.60;
    color: #0c1b15;
    overflow-wrap: break-word;
    word-break: break-word;
}

.i-richtext-view p, .i-richtext-view ul, .i-richtext-view ol { margin: 0; }
.i-richtext-view ul, .i-richtext-view ol { padding-left: 26px; }
.i-richtext-view li { margin: 0; }

.i-richtext-view a { color: #167a55; text-decoration: underline; }
.i-richtext-view a:hover { color: #1fa971; }

.i-richtext-view img {
    display: inline-block;
    vertical-align: middle;
    max-width: 100%;
    height: auto;
}

.i-richtext-view hr {
    border: none;
    border-top: 2px solid #c3cfc8;
    margin: 0.7rem 0;
}
.i-richtext-view hr.i-richtext-view-pagebreak { border-top: 1px dashed #84948c; }
