markup-text-editor {
    display: block;
    width: 100%;
    --markup-text-editor-surface-background: var(--cso-control-bg, #43ac6a0a);
    --markup-text-editor-surface-focus-background: var(--cso-control-bg-focus, #ffffff);
    --markup-text-editor-surface-border: var(--cso-border, #e2e8f0);
    --markup-text-editor-surface-shadow: var(--cso-control-shadow, inset 0 1px 2px rgba(15, 23, 42, 0.06));
    --markup-text-editor-surface-focus-border: var(--cso-teal-600, #008CBA);
    --markup-text-editor-surface-focus-outline: none;
    --markup-text-editor-surface-focus-shadow: var(--cso-control-shadow, inset 0 1px 2px rgba(15, 23, 42, 0.06)), 0 0 0 4px var(--cso-teal-100, #D6EDF4);
}

markup-text-editor .markup-text-editor {
    display: grid;
    gap: 6px;
    width: 100%;
}

markup-text-editor .markup-text-editor-label {
    font-weight: 700;
    font-size: 0.78rem;
    line-height: 1.35;
    color: var(--cso-ink, #0f172a);
}

markup-text-editor .markup-text-editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

markup-text-editor .markup-text-editor-toolbar-group,
markup-text-editor .markup-text-editor-mode-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
}

markup-text-editor .markup-text-editor-mode-group {
    display: inline-flex;
    flex-wrap: nowrap;
    gap: 0;
    padding: 3px;
    border: 1px solid var(--cso-border, #cbd5e1);
    border-radius: 999px;
    background: #ffffff;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.08);
}

markup-text-editor .markup-text-editor-toolbar-button,
markup-text-editor .markup-text-editor-mode-button {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    min-height: 32px;
    padding: 4px 8px;
    border: 1px solid rgba(100, 116, 139, 0.38);
    border-radius: 6px;
    background: #ffffff;
    color: #0f172a;
    font-size: 0.82rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    user-select: none;
}

markup-text-editor .markup-text-editor-mode-button {
    min-width: 56px;
    min-height: 26px;
    padding: 4px 10px;
    border: none;
    border-radius: 999px;
    background: transparent;
    font-weight: 600;
    color: #334155;
}

markup-text-editor .markup-text-editor-block-format {
    position: relative;
    display: inline-flex;
    align-items: center;
    min-height: 32px;
}

markup-text-editor .markup-text-editor-block-select {
    box-sizing: border-box;
    height: 32px;
    min-height: 32px;
    padding: 3px 30px 3px 8px;
    border: 1px solid rgba(100, 116, 139, 0.38);
    border-radius: 6px;
    background-color: #ffffff;
    color: #0f172a;
    font-size: 0.82rem;
    font-weight: 600;
}

markup-text-editor .markup-text-editor-toolbar-button:hover:not(:disabled),
markup-text-editor .markup-text-editor-block-select:hover:not(:disabled) {
    border-color: #2563eb;
    background: #eff6ff;
    color: #1e3a8a;
}

markup-text-editor .markup-text-editor-mode-button:hover:not(:disabled) {
    background: #eff6ff;
    color: #1e3a8a;
}

markup-text-editor .markup-text-editor-toolbar-button:focus-visible,
markup-text-editor .markup-text-editor-mode-button:focus-visible,
markup-text-editor .markup-text-editor-block-select:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

markup-text-editor .markup-text-editor-toolbar-button:disabled,
markup-text-editor .markup-text-editor-mode-button:disabled,
markup-text-editor .markup-text-editor-block-select:disabled {
    cursor: default;
    opacity: 0.52;
}

markup-text-editor .markup-text-editor-toolbar-button.is-active,
markup-text-editor .markup-text-editor-mode-button.is-active {
    border-color: #0f766e;
    background: #ccfbf1;
    color: #134e4a;
}

markup-text-editor .markup-text-editor-mode-button.is-active {
    border-color: transparent;
    background: var(--cso-teal-600, #008CBA);
    color: #ffffff;
}

markup-text-editor [data-tooltip]::after {
    position: absolute;
    z-index: 20;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    display: none;
    width: max-content;
    max-width: 220px;
    padding: 5px 7px;
    border-radius: 4px;
    background: #0f172a;
    color: #ffffff;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.2;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.18);
    content: attr(data-tooltip);
    pointer-events: none;
}

markup-text-editor [data-tooltip]:hover::after,
markup-text-editor [data-tooltip]:focus-visible::after {
    display: block;
}

markup-text-editor .markup-text-editor-icon {
    display: inline-grid;
    place-items: center;
    width: 18px;
    height: 18px;
    font-weight: 800;
    line-height: 1;
}

markup-text-editor .markup-text-editor-icon-code {
    width: 24px;
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-size: 0.76rem;
}

markup-text-editor .markup-text-editor-icon-clear {
    position: relative;
    font-size: 0.92rem;
}

markup-text-editor .markup-text-editor-icon-clear::after {
    position: absolute;
    width: 18px;
    height: 2px;
    transform: rotate(-35deg);
    border-radius: 999px;
    background: currentColor;
    content: "";
}

markup-text-editor .markup-text-editor-icon-list,
markup-text-editor .markup-text-editor-icon-numbered-list {
    grid-template-columns: 5px 12px;
    align-content: center;
    gap: 1px 3px;
    width: 20px;
    height: 16px;
}

markup-text-editor .markup-text-editor-icon-list .list-marker {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: currentColor;
}

markup-text-editor .markup-text-editor-icon-numbered-list .list-number {
    font-size: 0.48rem;
    line-height: 1;
}

markup-text-editor .markup-text-editor-icon-list .list-line,
markup-text-editor .markup-text-editor-icon-numbered-list .list-line {
    width: 12px;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
}

markup-text-editor .markup-text-editor-rich,
markup-text-editor .markup-text-editor-source {
    width: 100%;
    height: var(--markup-text-editor-surface-height, auto);
    box-sizing: border-box;
    border: 1px solid var(--markup-text-editor-surface-border, rgba(148, 163, 184, 0.44));
    border-radius: 8px;
    background: var(--markup-text-editor-surface-background);
    color: #0f172a;
    font-size: 0.95rem;
    line-height: 1.5;
    box-shadow: var(--markup-text-editor-surface-shadow, none);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

markup-text-editor .markup-text-editor-rich {
    min-height: var(--markup-text-editor-min-height, calc(var(--markup-text-editor-row-count, 8) * 1.5em));
    max-height: var(--markup-text-editor-max-height, clamp(180px, 38vh, 520px));
    padding: 12px;
    overflow: auto;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

markup-text-editor .markup-text-editor-source {
    min-height: var(--markup-text-editor-min-height, calc(var(--markup-text-editor-row-count, 8) * 1.5em));
    max-height: var(--markup-text-editor-max-height, clamp(180px, 38vh, 520px));
    padding: 12px;
    resize: vertical;
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-size: 0.88rem;
}

markup-text-editor .markup-text-editor-rich[contenteditable="false"] {
    cursor: default;
}

markup-text-editor .markup-text-editor-rich:focus,
markup-text-editor .markup-text-editor-source:focus {
    border-color: var(--markup-text-editor-surface-focus-border);
    outline: var(--markup-text-editor-surface-focus-outline);
    outline-offset: var(--markup-text-editor-surface-focus-outline-offset, 0);
    background: var(--markup-text-editor-surface-focus-background);
    box-shadow: var(--markup-text-editor-surface-focus-shadow);
}

markup-text-editor .markup-text-editor-rich[aria-readonly="true"],
markup-text-editor .markup-text-editor-source[readonly] {
    background: var(--cso-control-bg-readonly, #f8fafc);
    color: var(--cso-muted, #64748b);
    border-color: rgba(148, 163, 184, 0.35);
    box-shadow: none;
    cursor: default;
}

markup-text-editor .markup-text-editor-rich code {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-size: 0.9em;
    padding: 0.08rem 0.32rem;
    border-radius: 0.35rem;
    background: rgba(15, 23, 42, 0.08);
    color: #0f172a;
}

markup-text-editor .markup-text-editor-rich blockquote {
    margin: 0.5rem 0;
    padding: 0.25rem 0 0.25rem 0.75rem;
    border-left: 3px solid #0f766e;
    color: #334155;
}

markup-text-editor .markup-text-editor-rich p,
markup-text-editor .markup-text-editor-rich ul,
markup-text-editor .markup-text-editor-rich ol,
markup-text-editor .markup-text-editor-rich blockquote {
    margin-top: 0.45rem;
    margin-bottom: 0.45rem;
}

markup-text-editor .markup-text-editor-rich h1,
markup-text-editor .markup-text-editor-rich h2,
markup-text-editor .markup-text-editor-rich h3,
markup-text-editor .markup-text-editor-rich h4,
markup-text-editor .markup-text-editor-rich h5,
markup-text-editor .markup-text-editor-rich h6 {
    margin-top: 0.6rem;
    margin-bottom: 0.35rem;
    color: #0f172a;
    line-height: 1.25;
}

@media (max-width: 720px) {
    markup-text-editor .markup-text-editor-toolbar {
        align-items: stretch;
    }

    markup-text-editor .markup-text-editor-toolbar-group,
    markup-text-editor .markup-text-editor-mode-group {
        width: 100%;
    }

    markup-text-editor .markup-text-editor-block-format {
        flex: 1 1 180px;
    }
}
